Insert values into Table using a form

pkan71

New member
Local time
Today, 13:24
Joined
Sep 2, 2011
Messages
7
I have a table named tblScanned with one field ProctorID. I have a form named Form1 with a unbound box called Test.

The ProctorID field is a number.

Below is the code. I compiled the code and I get a syntax error message.

After I scan in the number, I want to clear out the unbound box called Test.

Any help would be appreciated.

Thanks.

Patrick


Private Sub Test_Click()
Dim strSQL As Integer
strSQL = "Insert Into tblScanned(ProctorID) Values ('"&Me!Test&"');"
Debug.Print strSQL
CurrentDb.Execute strSQL
Me!Test = " "
End Sub
 
This is certainly a problem:

Dim strSQL As Integer

You want String.
 
Hi Paul,

I changed it to a String

But I still get a Compile Error: Syntax Error.

See Below.

Thanks for your help.

Private Sub Test_Click()
Dim strSQL As Integer
strSQL = "Insert Into tblScanned(ProctorID) Values ('"&Me!Test&"');"
Debug.Print strSQL
CurrentDb.Execute strSQL
Me!Test = " "
End Sub
 
That still has it as an Integer. I'd put spaces in where your concatenation happens too, so it's not all jammed together:

strSQL = "Insert Into tblScanned(ProctorID) Values ('" & Me!Test & "');"

I assume that ProctorID is a Text data type?
 
Hi Paul,

The ProctorID is a Number data type.

Thanks.

Patrick
 
Then you don't want the single quotes:

strSQL = "Insert Into tblScanned(ProctorID) Values (" & Me!Test & ");"
 

Users who are viewing this thread

Back
Top Bottom