VBA OpenRecordset (1 Viewer)

Jamster45

New member
Local time
Today, 15:13
Joined
Aug 15, 2018
Messages
7
Hi There,

I want to retrieve a value from a table. The value have to go to an other field on the same form.

However, its not working because of error ''syntax error, operator is missing".

The value in the table (FactuurFactuurnummerFN) is text and contains letters and numbers.

Here is the code:

Dim db As Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT * FROM factuur WHERE FactuurFactuurnummerFN=" & Me.factuurnummerFN)

Me.StatusFactuur = rs!Factuur_status
End sub

Can someone help me and explain whats going wrong?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 18:13
Joined
May 21, 2018
Messages
8,525
I am assuming you want tableName.FieldName
Factuur.FactuurnummerFN
but since only one table the tablename is not needed.
 

Gasman

Enthusiastic Amateur
Local time
Today, 23:13
Joined
Sep 21, 2011
Messages
14,231
Why grab all that data, when a DLookup would work just as well.?
Alternatively, just use Select Factuur_status
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 17:13
Joined
Feb 28, 2001
Messages
27,138
As to the error, is there any chance that the Me.factuurnummerFN control happens to be blank at the moment this is run? Or can it contain quotes or apostrophes as a form of punctuation? Or can there be a space embedded in the control's contents? For the latter, I don't mean leading or trailing spaces, but rather something in the middle of the imported string.

Whenever you are doing substitution from a form or something you have input another way, you are bringing something "foreign" into the string that you are building. If you don't take steps to protect yourself from unexpectedly oddball strings, you invite trouble.

"Missing operator" USUALLY means there is an extraneous character somewhere and you have confused the string parser.
 

Jamster45

New member
Local time
Today, 15:13
Joined
Aug 15, 2018
Messages
7
Ok guys, Thanks for your advice.

I was missing some quotes, stupid me
 

Gasman

Enthusiastic Amateur
Local time
Today, 23:13
Joined
Sep 21, 2011
Messages
14,231
Ok guys, Thanks for your advice.

I was missing some quotes, stupid me

I tend to put my constructed sql into a string, then debug.print it to see if it turns out as I expect it should. ;)
 

Users who are viewing this thread

Top Bottom