Keep getting run time error '3134' for my insert statement in MS Access VBA (1 Viewer)

luzz

Registered User.
Local time
Today, 14:09
Joined
Aug 23, 2017
Messages
346
Hello everyone,

I have written a insert statement to insert my data into my Access table and i keep getting error when i click on save to insert into my table.
Below is my code:

If Me.txtCompanyCode.Tag & "" = "" Then
CurrentDb.Execute "INSERT INTO mxdPONumber(CompanyCode)" & _
" VALUE('" & Me.txtCompanyCode & "')"

End If

Thank you.
 

JHB

Have been here a while
Local time
Today, 23:09
Joined
Jun 17, 2012
Messages
7,732
.. Now another issue is that i have error "Too few parameter, expected 1."
Is CompanyCode a number or a text field type?
If number remove both '.
Code:
" VALUE([B][COLOR=Red]'[/COLOR][/B]" & Me.txtCompanyCode & "[B][COLOR=Red]'[/COLOR][/B])"
 

luzz

Registered User.
Local time
Today, 14:09
Joined
Aug 23, 2017
Messages
346
Is CompanyCode a number or a text field type?
If number remove both '.
Code:
" VALUE([B][COLOR=Red]'[/COLOR][/B]" & Me.txtCompanyCode & "[B][COLOR=Red]'[/COLOR][/B])"

Hi, is a text ;)
Below is my code:
txtCode -> text
txtYearCode-> Number
txtPONumber - > Number

If Me.txtCode.Tag & "" = "" Then

CurrentDb.Execute "INSERT INTO RunningNo(CompanyCode,YearCode,PONumber)" & _
" Values (" & Me.txtCode & ",'" & Me.txtYearCode & " & Me.txtPONumber & " ')"

End If
 

JHB

Have been here a while
Local time
Today, 23:09
Joined
Jun 17, 2012
Messages
7,732
Hi, is a text ;)
Below is my code:
txtCode -> text
txtYearCode-> Number
txtPONumber - > Number

If Me.txtCode.Tag & "" = "" Then

CurrentDb.Execute "INSERT INTO RunningNo(CompanyCode,YearCode,PONumber)" & _
" Values (" & Me.txtCode & ",'" & Me.txtYearCode & " & Me.txtPONumber & " ')"

End If
You've the ' in wrong places + missing a ,:
Code:
CurrentDb.Execute "INSERT INTO RunningNo(CompanyCode,YearCode,PONumber)" & _
         " Values ([B][COLOR=Red]'[/COLOR][/B]" & Me.txtCode & "[B][COLOR=Red]'[/COLOR][/B]," & Me.txtYearCode & [B][COLOR=Red]","[/COLOR][/B] & Me.txtPONumber & ")"
 

luzz

Registered User.
Local time
Today, 14:09
Joined
Aug 23, 2017
Messages
346
You've the ' in wrong places + missing a ,:
Code:
CurrentDb.Execute "INSERT INTO RunningNo(CompanyCode,YearCode,PONumber)" & _
         " Values ([B][COLOR=Red]'[/COLOR][/B]" & Me.txtCode & "[B][COLOR=Red]'[/COLOR][/B]," & Me.txtYearCode & [B][COLOR=Red]","[/COLOR][/B] & Me.txtPONumber & ")"

Hi i have added in the ' now i am getting syntax error.
I have attached a copy of my error above.
 

JHB

Have been here a while
Local time
Today, 23:09
Joined
Jun 17, 2012
Messages
7,732
Could you post your database with some sample data + name of the form in which the error is.

Ps. I can't see you've attached anything! :confused:
 

luzz

Registered User.
Local time
Today, 14:09
Joined
Aug 23, 2017
Messages
346
Could you post your database with some sample data + name of the form in which the error is.

Ps. I can't see you've attached anything! :confused:

Ohhh, never mind! I have solved my error already! Thankyou!
 

JHB

Have been here a while
Local time
Today, 23:09
Joined
Jun 17, 2012
Messages
7,732
And the problem/solution was?
 

Users who are viewing this thread

Top Bottom