compile error: expected: expression (1 Viewer)

AC-Dev

What say you, good sir?
Local time
Today, 10:47
Joined
Jun 20, 2011
Messages
81
Good Morning/Afternoon/Night (wherever you are)

I am getting this error when i attempt to run this code and i am not sure what is happening????? i dont see any errors with this.

Code:
Dim txtAcc As String

txtAcc = SELECT Employees.Access_Level FROM Employees WHERE Employee_ID = XXXXXXXX)
help please:)
 

JANR

Registered User.
Local time
Today, 15:47
Joined
Jan 21, 2009
Messages
1,623
Code:
Dim txtAcc As String

txtAcc = [B][COLOR=red]"[/COLOR][/B]SELECT Employees.Access_Level FROM Employees WHERE Employee_ID = XXXXXXXX[B][COLOR=red]"[/COLOR][/B]

Use quotes around stringexpression

JR
 

AC-Dev

What say you, good sir?
Local time
Today, 10:47
Joined
Jun 20, 2011
Messages
81
thanks for the reply,

just have one more giving me a similar error

Code:
INSERT INTO [China Ops] [Amendment Number] VALUES (andnum) WHERE "Item='" & glb_CHIITEM & "'"

compile error: expected: end of statement
 

JANR

Registered User.
Local time
Today, 15:47
Joined
Jan 21, 2009
Messages
1,623
You cannot use Values if you use a where-clause, you must use Select.

I assume andnum is a number variable so:

Code:
"Insert Into [China Ops] ([Amnedment Number]) Select " & andnum & " Where Item='" & glb_CHIITEM & "'"

JR
 

AC-Dev

What say you, good sir?
Local time
Today, 10:47
Joined
Jun 20, 2011
Messages
81
You cannot use Values if you use a where-clause, you must use Select.

I assume andnum is a number variable so:

Code:
"Insert Into [China Ops] ([Amnedment Number]) Select " & andnum & " Where Item='" & glb_CHIITEM & "'"
JR

correct - amdnum is a variable

okay i made the adjustments (aka copy and paste) and im getting another compile error

Expected: line number or label or statement or end of statement
doesnt make sense to me :s
 

JANR

Registered User.
Local time
Today, 15:47
Joined
Jan 21, 2009
Messages
1,623
A function or a sub is requiered to execute any VBA code, yes

ex:
Code:
Private Sub MyButton_Click()
Dim s As String
s = " Insert Into MyTable (FName) Select 'Fred' Where Id=1"
Currentdb.Execute s, dbFailOnError
End Sub

JR
 

AC-Dev

What say you, good sir?
Local time
Today, 10:47
Joined
Jun 20, 2011
Messages
81
ahhhhhhh ic my error. i have to declare it as a variable and then execute it.

i got another error when i do this but i am going to attempt and troubleshoot it first cause i feel like im being a pest :)
 

AC-Dev

What say you, good sir?
Local time
Today, 10:47
Joined
Jun 20, 2011
Messages
81
alright, no idea what to do.
hour and a half later and im still confused

my new error is:

Runtime error 3075:
Syntax error (missing operator) in query expression '20 WHERE ([Item]='200')'

Code:
s = "INSERT INTO [China Ops] ([Amendment Number]) SELECT " &  Me.txtAmdNum & " WHERE ([Item]='" & glb_CHIITEM & "')"

'test variables
MsgBox glb_CHIITEM
MsgBox s

CurrentDb.Execute s, dbFailOnError
 

JANR

Registered User.
Local time
Today, 15:47
Joined
Jan 21, 2009
Messages
1,623
Runtime error 3075:
Syntax error (missing operator) in query expression '20 WHERE ([Item]='200')'

The error gives you a hint on the error, numbers do not use quotationmarks, remove the qoutes around glb_CHIITEM


...." WHERE [Item]=" & glb_CHIITEM

JR
 

Painteagle

New member
Local time
Today, 09:47
Joined
May 23, 2013
Messages
1
I am getting the same Error message.
I am just attempting to have a function that checks a group of checkboxes when a commandButton is clicked.
The code is as follows:

Code:
Private Sub CommandButton1_Click()
CheckBox1.Value = True
CheckBox2.Value = True
CheckBox3.Value = True
CheckBox4.Value = True
CheckBox5.Value = True
CheckBox6.Value = True
End Sub
 

pr2-eugin

Super Moderator
Local time
Today, 14:47
Joined
Nov 30, 2011
Messages
8,494
Painteagle, Welcome to AWF.. Could you please start a new thread describing your issue, so that you will not be limited to amount of help you get?
 

Users who are viewing this thread

Top Bottom