Re: SQL HANGS



"DS" <bootybox@xxxxxxxxxxxxx> wrote in message
news:6AoJg.60$6z5.58@xxxxxxxxxxxx
This works unless the TxtCCExpDate field is left blank. If I leave
that field blank which it can sometimes be then I get a Syntax Error
in Date Query Expression. Any way of fixing this so that I can leave
the TxtCCExpDate field empty if I need to?
Thanks
DS

Me.TxtDepositID = Nz(DMax("[DepositID]", "Deposits"), 0) + 1
CurrentDb.Execute "INSERT Into

Deposits(DepositID,DepositDate,DepositAmount,Customer,Employee,Manager,M
emo,DepositType,CardNumber,ExpDate)
" & _
"VALUES('" & Forms!AddDeposit!TxtDepositID & "'," & _
"#" & Forms!AddDeposit!TxtDepositDate & "#," & _
"'" & Forms!AddDeposit!TxtDepositAmount & "'," & _
"'" & Forms!AddDeposit!TxtCussID & "'," & _
"'" & Forms!AddDeposit!TxtEmployee & "'," & _
"'" & Forms!AddDeposit!TxtManager & "'," & _
"'" & Forms!AddDeposit!TxtMemo & "'," & _
"'" & Forms!AddDeposit!TxtDepositType & "'," & _
"#" & Forms!AddDeposit!TxtCCExpDate & "#," & _
"'" & Forms!AddDeposit!TxtCCNumber & "')"

Please don't use the word "hangs" in describing your problem unless
whatever is happening causes the program to stop responding. It's
misleading. Just getting an error is not "hanging", nor is it
"crashing", as people sometimes write.

As for your problem: you need to check whether the control is Null, and
substitute the keyword "Null" in the SQL string in place of the date
literal you would otherwise build. For example,

[ ... ]
IIf(IsNull(Forms!AddDeposit!TxtCCExpDate), _
"Null,", _
"#" & Forms!AddDeposit!TxtCCExpDate & "#,") & _
[ ... ]

It would be better, though, to format date literals into mm/dd/yyyy
format, to avoid any ambiguity:

[ ... ]
IIf(IsNull(Forms!AddDeposit!TxtCCExpDate), _
"Null", _
Format(Forms!AddDeposit!TxtCCExpDate, "\#mm/dd/yyyy\#")) & _
"," & _
[ ... ]

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


.



Relevant Pages

  • Comma in query expression
    ... I believe that it is the format of the textfield, but I don't know how to fix ... Syntax error in query expression '=Brady, Tom'. ...
    (microsoft.public.access.queries)
  • Re: Calling a Function or a Procedure
    ... Which format to use for Sub procedures is a matter of style. ... parameter is ByRef then any changes made to the value in MySub are lost ... The syntax error with multiple arguments comes up because if you try to use ...
    (microsoft.public.vb.general.discussion)
  • Re: sending a query to access in asp.net
    ... I don't know access but ANSI SQL needs single quotes '*@nombre*' around the ... > Exception Details: System.Data.OleDb.OleDbException: Syntax error (missing ... > operator) in query expression 'nombre like @nombre'. ... > dim objconn as oledbconnection ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Syntax problem - probably with partdate?
    ... (i.e. Run time error 3075 Syntax error (missing operator) ... Syntax error (missing operator) in query expression ...
    (microsoft.public.access.formscoding)
  • Re: Using a list or combo box to set the value for a report- one m
    ... OK I get the following error: Syntax error in string in query expression ... Miles City Field Office ... You can place this code in AfterUpdate event of the combobox or in Click ...
    (microsoft.public.access.reports)