A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

SQL HANGS



 
 
Thread Tools Display Modes
  #1  
Old August 30th, 2006, 11:47 PM posted to microsoft.public.access.forms
DS
external usenet poster
 
Posts: 285
Default SQL HANGS

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,Custo mer,Employee,Manager,Memo,DepositType,CardNumber,E xpDate)
" & _
"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 & "')"
  #2  
Old September 1st, 2006, 06:00 PM posted to microsoft.public.access.forms
Dirk Goldgar
external usenet poster
 
Posts: 1,164
Default SQL HANGS

"DS" wrote in message

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,Custo mer,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)


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:21 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.