473,569 Members | 2,790 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help with syntax (missing operator?)

I have a piece of code (below) that is giving me fits. I copied this code from elsewhere on the net, and I have been fiddling with the quotations in the Where clause, as that seems to be the problem. Depending on what I change, I get compile errors, syntax errors, etc.

I have an unbound combo box (cboEffDate). The recordsource for this box is a simple query that shows the effective dates stored in tblCapacity.Eff Date. What I want to happen is for the user to select an Effective Date from the drop down, then have my text boxes on the form populate with the field values associated with the effective date. Once those fields are populated with the correct set of variables, there are some calculations.

The error is in the "where" clause.
Also, the field [EffDate] is a short date type in the table. The cboEffDate is also formated for short date.


Expand|Select|Wrap|Line Numbers
  1. Private Sub cboEffDate_AfterUpdate()
  2.     ' Pull info out of SQL View.
  3.  
  4.     Dim db As Database
  5.     Dim rs As Recordset
  6.  
  7.     Set db = CurrentDb
  8.     Set rs = db.OpenRecordset("SELECT * " & _
  9.     "FROM tblCapacity " & _
  10.     "WHERE [EffDate] = " & Me.cboEffDate.Value & "")
  11.     Me.txtFieldCap = rs![Field Inlet Capacity]
  12.     Me.txtT1Start = rs![T1 Start Date]
  13.     Me.txtT1End = rs![T1 End Date]
  14.     Me.txtT1Inlet = rs![T1 Inlet Gas]
  15.     Me.txtT1Residue = rs![T1 Residue Design]
  16.     Me.txtT1Fuel = rs![T1 Fuel]
  17. End Sub
Oct 21 '10 #1
23 1657
dsatino
393 Contributor
"WHERE [EffDate] = #" & Me.cboEffDate.V alue & "#")

You need to enclose dates with the # character for Access queries.
Oct 21 '10 #2
I typed:
"WHERE [EffDate] = #" & Me.cboEffDate.V alue & "#")

Now I get runtime 3075:
Syntax error in date in query expression 'EffDate = #'

I wonder if I have an extra space somewhere that I should not.
Oct 21 '10 #3
Now I am getting a different error:
Expand|Select|Wrap|Line Numbers
  1. RunTime 3075
  2. Syntax error in date in query expression '[EffDate] = #'
here is what I have currently:
"WHERE [EffDate] = #" & Me.cboEffDate.V alue & "#")
Oct 21 '10 #4
dsatino
393 Contributor
Sorry, try this:

Expand|Select|Wrap|Line Numbers
  1. "WHERE tblCapacity.EffDate = #" & Me.cboEffDate.Value & "#") 
  2.  
Oct 21 '10 #5
Same error, unfortunately.

Syntax error in date in query expression 'tblCapacity.Ef fDate = #'

Any other ideas/approaches are appreciated!
Oct 21 '10 #6
NeoPa
32,564 Recognized Expert Moderator MVP
Audrey,

This is a problem many have trouble with, and few understand fully. The hashes (#) are important, but not the only issue when dealing with date literals. See Literal DateTimes and Their Delimiters (#) for the full explanation.

To help with ypour specific problem (should you still need it after reviewing the article) it would help if you were to post the SQL itself, rather than the VBA which creates the SQL indirectly. To get this replace your lines #8 through #10 with :
Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT * " & _
  2.          "FROM [tblCapacity] " & _
  3.          "WHERE ([EffDate]=#" & Format(, "m/d/yyyy") & "#)"
  4. Debug.Print strSQL
  5. Set rs = db.OpenRecordset(strSQL)
and also add this line after #5 :
Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
I assume your error is occurring at line #8. This is always well worth including in the description of your problem of course.
Oct 21 '10 #7
NeoPa - Thank you for taking the time to help me.

I did as you suggested, and now I get a compile error.

Here is the code as it is currently (with your changes):

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboEffDate_AfterUpdate()
  2.     ' Pull info out of SQL View.
  3.  
  4.     Dim db As Database
  5.     Dim rs As Recordset
  6.     Dim strSQL As String
  7.  
  8.     Set db = CurrentDb
  9.     strSQL = "SELECT * " & _
  10.              "FROM [tblCapacity] " & _
  11.              "WHERE ([EffDate]=#" & Format(, "m/d/yyyy") & "#)"
  12.     Debug.Print strSQL
  13.     Set rs = db.OpenRecordset(strSQL)
  14.     Me.txtFieldCap = rs![Field Inlet Capacity]
  15.     Me.txtT1Start = rs![T1 Start Date]
  16.     Me.txtT1End = rs![T1 End Date]
  17.     Me.txtT1Inlet = rs![T1 Inlet Gas]
  18.     Me.txtT1Residue = rs![T1 Residue Design]
  19.     Me.txtT1Fuel = rs![T1 Fuel]
  20. End Sub
The error is:
Compile Error: Argument not optional

The line:
Expand|Select|Wrap|Line Numbers
  1.    strSQL = "SELECT * " & _
  2. is highlighted in yellow. 
There is nothing in the "immediate" box when I do a control G either.
Oct 21 '10 #8
dsatino
393 Contributor
your format function is missing the item it's supposed to be formatting. You need to reference the date you want to format.
Oct 21 '10 #9
Ok that makes sense.

However, the date will be selected from a combo box that is already formated to the short date. Perhaps the point of NeoPa's code was to make sure it is in the proper form.

Not sure where to put the reference to the combo box though. After the formating code?
Oct 21 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

29
2477
by: shank | last post by:
1) I'm getting this error: Syntax error (missing operator) in query expression on the below statement. Can I get some advice. 2) I searched ASPFAQ and came up blank. Where can find the "rules" for when and how to use single quotes and double quotes in ASP? thanks! ---------------------- SQL = SQL & "WHERE '" &...
3
9517
by: Mark | last post by:
Hi - I can get this to work in SQL Server - but when also trying to make the application compatible with MS Access I get an error: Select tblfaqnetgroups.group_name from tblfaqnetroles Inner Join tblfaqnetgroups ON tblfaqnetroles.group_id = tblfaqnetgroups.group_id Inner Join tblaccess ON tblfaqnetroles.user_id = tblaccess.user_id AND...
4
18039
by: dcarson | last post by:
I've read about this error in several other discussions, but still can't seem to pinpoint the problem with my code. Everything seemed to be working fine for some time, but it now tends to bomb out on me for some reason. The Summary field is pulled from a Rich Text Editor that allows HTML formatting and appears to be the culprit, but I just...
1
6857
by: Alan Murrell | last post by:
Hello, One of our web hosting clients is getting the following error when someone tried to log in form their login page: --- ODBC ERROR --- Microsoft OLE DB Provider for ODBC Drivers error '80040e14' Syntax error (missing operator) in query expression 'userid= AND password='''.
3
5520
by: Lumpierbritches | last post by:
Syntax Error (missing operator) in query expression =BLANK'S MOLLIE-PRINCE BRUISER-3/14/2004-03 AnimalID is correct. I'm trying to open with a command button or double click the frmAnimal from a subform that uses the same table, is that my problem? If I remove the criteria from the expression, it opens the form, but to show every record.
4
18207
by: khan | last post by:
getting, error, 3075 Syntax Error (Missing Operator) in query expression '8WHERE .=1' Dim TotalQty As Integer TotalQty = DLookup("", "", "=" & Forms!!)
3
4921
by: access baby | last post by:
I hava a date parameter filter query but it shows error Syntax error missing operator in query experssion can some one please help where am i going wrong in expression SELECT copyorderdtl * from copyorderdtl where(((cr_created_date)is Null) and ((cr_statusupdt_date)=)) OR (((cr_created_date) is not null and (cr_statusupdt_Date)=));
4
2321
by: nerd4access | last post by:
Hello all! I am not new to access, but new to coding (and posting). I have a database that I have created and need some help with a login form. When a user opens the database, a form pops up asking for a username and password. They can choose their name from a combobox and enter apassword into a textbox. If the default password is...
0
7609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7921
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7666
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6278
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.