J
JimBurke via AccessMonster.com
I have been using form control values in my query criteria forever. All of
the sudden Access is giving me an error with some new queries I've created
and I can't for the life of me figure out why. I have one field that needs
criteria. If I hard code the actual value in the query it runs fine. If I go
into the query and execute it directly after I have the value in the form
control that works fine as well. When I run the query via VBA I get the error
'Invalid SQL Statement: Expected Delete, Insert...".
Here is my code:
dim cn As ADODB.Connection
Set cn = CurrentProject.Connection
Forms!frmPatientInfo!txtBillID = BillID
rstBillOrig.Open "qryGetOriginalBillValidation", cn, adOpenForwardOnly,
adLockOptimistic
If I step throught the code I know that the BillID value is assigned to the
form control value. In the query criteria I pasted that form control name -
Access adds the brackets, so in the criteria field in the query it has
[Forms]![frmPatientInfo]![txtBillID]
LIke I said, if I just hard code a value it works fine. When I run it with
the form control value when it has that exact same value I get the error. I
even took the SQL text (cut and pasted it from the query) and formatted it
and assigend it to a string variable, and it works fine then also. In that
case I end up with something like
SQLText = "SELECT field1 FROM table1 " & _
"WHERE field2 = " & [Forms]![frmPatientInfo]![txtBillID]
rstBillOrig.Open SQLText, cn, adOpenForwardOnly, adLockOptimistic
And that works! I've always used form controls in my query criteria and
cannot understand why this isn't working. I'm baffled. I have lots of other
existing querys that are used throughout the application that use form
control values for criteria and they are all still functioning fine.
the sudden Access is giving me an error with some new queries I've created
and I can't for the life of me figure out why. I have one field that needs
criteria. If I hard code the actual value in the query it runs fine. If I go
into the query and execute it directly after I have the value in the form
control that works fine as well. When I run the query via VBA I get the error
'Invalid SQL Statement: Expected Delete, Insert...".
Here is my code:
dim cn As ADODB.Connection
Set cn = CurrentProject.Connection
Forms!frmPatientInfo!txtBillID = BillID
rstBillOrig.Open "qryGetOriginalBillValidation", cn, adOpenForwardOnly,
adLockOptimistic
If I step throught the code I know that the BillID value is assigned to the
form control value. In the query criteria I pasted that form control name -
Access adds the brackets, so in the criteria field in the query it has
[Forms]![frmPatientInfo]![txtBillID]
LIke I said, if I just hard code a value it works fine. When I run it with
the form control value when it has that exact same value I get the error. I
even took the SQL text (cut and pasted it from the query) and formatted it
and assigend it to a string variable, and it works fine then also. In that
case I end up with something like
SQLText = "SELECT field1 FROM table1 " & _
"WHERE field2 = " & [Forms]![frmPatientInfo]![txtBillID]
rstBillOrig.Open SQLText, cn, adOpenForwardOnly, adLockOptimistic
And that works! I've always used form controls in my query criteria and
cannot understand why this isn't working. I'm baffled. I have lots of other
existing querys that are used throughout the application that use form
control values for criteria and they are all still functioning fine.