Hi,
I am glad that worked out for you. I really had to smack myself in the forehead after Old Pedant's post.
Generally when you try to run a SQL string at the same time you are taking data, you will get a data type mismatch or similar error. Also, if you are not doing validation, then you might run into problems if your table requires certain data to have been inserted.
Data validation can be done at the table level. This throws an error that your user's might not appreciate. It is very effective, however, and works regardless of where the data is coming from, so alleviates the need to code on the forms.
I usually will check the data types in the code as I am assigning the control values to a variable. For required data, I can use:
If IsNull(Me.TextControl) Or Me.TextControl = "" Then
MsgBox "Please enter a value.", vbInformation
Exit Sub
Else
sString = Me.TextControl
End If
Or for Integers or Long variables:
If IsNull(Me.NumberControl) Or Me.NumberControl = 0 Then
MsgBox "Please enter a value.", vbInformation
Exit Sub
Else
lNumber = Me.NumberControl
End If
If the value is not required, I could use:
If IsNull(Me.TextControl) Or Me.TextControl = "" Then
sString = ""
Else
sString = Me.TextControl
End If
I use this method a lot when I use SQL Server as the back end because SQL Server throws some ominous errors, and can also give itself away in the error text.
Once you have your data validated, then you can build the SQL string, then run the SQL string. The nice thing with this structure is, if you get an error, you know just where it is in your code/processes.
Did that help?
mmcdonal
Look it up at:
http://wrox.books24x7.com