Go Back   Access World Forums > Microsoft Access Discussion > Forms

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 08-03-2011, 05:24 AM   #1
AC-Dev
What say you, good sir?
 
Join Date: Jun 2011
Location: Toronto (GTA), Ontario
Posts: 81
Thanks: 12
Thanked 0 Times in 0 Posts
AC-Dev is on a distinguished road
compile error: expected: expression

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

AC-Dev is offline   Reply With Quote
Old 08-03-2011, 05:27 AM   #2
JANR
Newly Registered User
 
Join Date: Jan 2009
Location: Norway
Posts: 1,623
Thanks: 7
Thanked 167 Times in 160 Posts
JANR has a spectacular aura about JANR has a spectacular aura about
Re: compile error: expected: expression

Code:
Dim txtAcc As String

txtAcc = "SELECT Employees.Access_Level FROM Employees WHERE Employee_ID = XXXXXXXX"
Use quotes around stringexpression

JR
JANR is offline   Reply With Quote
Old 08-03-2011, 05:46 AM   #3
AC-Dev
What say you, good sir?
 
Join Date: Jun 2011
Location: Toronto (GTA), Ontario
Posts: 81
Thanks: 12
Thanked 0 Times in 0 Posts
AC-Dev is on a distinguished road
Re: compile error: expected: expression

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

AC-Dev is offline   Reply With Quote
Old 08-03-2011, 05:57 AM   #4
JANR
Newly Registered User
 
Join Date: Jan 2009
Location: Norway
Posts: 1,623
Thanks: 7
Thanked 167 Times in 160 Posts
JANR has a spectacular aura about JANR has a spectacular aura about
Re: compile error: expected: expression

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
JANR is offline   Reply With Quote
Old 08-03-2011, 06:07 AM   #5
AC-Dev
What say you, good sir?
 
Join Date: Jun 2011
Location: Toronto (GTA), Ontario
Posts: 81
Thanks: 12
Thanked 0 Times in 0 Posts
AC-Dev is on a distinguished road
Re: compile error: expected: expression

Quote:
Originally Posted by JANR View Post
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
AC-Dev is offline   Reply With Quote
Old 08-03-2011, 06:07 AM   #6
JANR
Newly Registered User
 
Join Date: Jan 2009
Location: Norway
Posts: 1,623
Thanks: 7
Thanked 167 Times in 160 Posts
JANR has a spectacular aura about JANR has a spectacular aura about
Re: compile error: expected: expression

A useful site on how to bulid SQL string an execute it in VBA :http://www.baldyweb.com/BuildSQL.htm

JR
JANR is offline   Reply With Quote
Old 08-03-2011, 06:16 AM   #7
AC-Dev
What say you, good sir?
 
Join Date: Jun 2011
Location: Toronto (GTA), Ontario
Posts: 81
Thanks: 12
Thanked 0 Times in 0 Posts
AC-Dev is on a distinguished road
Re: compile error: expected: expression

Quote:
Originally Posted by JANR View Post
A useful site on how to bulid SQL string an execute it in VBA :http://www.baldyweb.com/BuildSQL.htm

JR
ohhhh so i have to make this in a function and then execute it from there?

AC-Dev is offline   Reply With Quote
Old 08-03-2011, 06:28 AM   #8
JANR
Newly Registered User
 
Join Date: Jan 2009
Location: Norway
Posts: 1,623
Thanks: 7
Thanked 167 Times in 160 Posts
JANR has a spectacular aura about JANR has a spectacular aura about
Re: compile error: expected: expression

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
JANR is offline   Reply With Quote
Old 08-03-2011, 06:54 AM   #9
AC-Dev
What say you, good sir?
 
Join Date: Jun 2011
Location: Toronto (GTA), Ontario
Posts: 81
Thanks: 12
Thanked 0 Times in 0 Posts
AC-Dev is on a distinguished road
Re: compile error: expected: expression

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 is offline   Reply With Quote
Old 08-03-2011, 08:15 AM   #10
AC-Dev
What say you, good sir?
 
Join Date: Jun 2011
Location: Toronto (GTA), Ontario
Posts: 81
Thanks: 12
Thanked 0 Times in 0 Posts
AC-Dev is on a distinguished road
Re: compile error: expected: expression

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
AC-Dev is offline   Reply With Quote
Old 08-03-2011, 09:49 AM   #11
JANR
Newly Registered User
 
Join Date: Jan 2009
Location: Norway
Posts: 1,623
Thanks: 7
Thanked 167 Times in 160 Posts
JANR has a spectacular aura about JANR has a spectacular aura about
Re: compile error: expected: expression

Quote:
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
JANR is offline   Reply With Quote
Old 05-23-2013, 08:06 AM   #12
Painteagle
Newly Registered User
 
Join Date: May 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Painteagle is on a distinguished road
Re: compile error: expected: expression

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
Painteagle is offline   Reply With Quote
Old 08-23-2013, 02:59 AM   #13
pr2-eugin
Super Moderator
 
pr2-eugin's Avatar
 
Join Date: Nov 2011
Location: Bournemouth, UK
Posts: 8,498
Thanks: 68
Thanked 2,067 Times in 2,014 Posts
pr2-eugin has a spectacular aura about pr2-eugin has a spectacular aura about pr2-eugin has a spectacular aura about
Re: compile error: expected: expression

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?

__________________
Regards,
Paul Eugin

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
!
Windows 7 Professional, MS Access 2010
---------------------------------------------------------------------------------------------------------------------
If the above post has helped you, please click the scales
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
or click the 'Thumbs up'. Cheers.

---------------------------------------------------------------------------------------------------------------------



pr2-eugin is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Compile error: Expected: end of statement SoxPats83 Forms 10 05-26-2010 09:31 AM
Compile Error: Expected end of statement tranchemontaigne Modules & VBA 4 09-24-2009 12:48 AM
Compile Error Expected: end of statement dallnsn Modules & VBA 6 08-23-2008 04:42 AM
Compile Error: Expected: = MaxNEMC Modules & VBA 4 01-15-2003 10:07 AM
Compile Error - Expected Expression meandmyhorse Modules & VBA 1 08-01-2002 06:26 PM




All times are GMT -8. The time now is 09:12 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World