Not Sure what this systax error is all about (1 Viewer)

anishkgt

Registered User.
Local time
Today, 15:15
Joined
Nov 4, 2013
Messages
384
I get a syntax error for this
Code:
DLookUp("[LockNum]","tblImportLock","[Open]=1")
LockNum is of DataType Number

I used macro to code the form. It just checks a filed value for 1 or 0. It had been working but just today an error poped-up.
 

isladogs

MVP / VIP
Local time
Today, 13:15
Joined
Jan 14, 2017
Messages
18,207
You haven't said what error occurs.
Without that, all we can do is guess the problem.

My guess is you get invalid use of null error.
If so, wrap your expression in the Nz function
Nz(DLookup(.....,"')

Also, what is the datatype for the Open field?
If it's yes/no (Boolean) use false instead of 0.

Finally, the [] brackets aren't needed in your case as you have no spaces in field names
 

anishkgt

Registered User.
Local time
Today, 15:15
Joined
Nov 4, 2013
Messages
384
the error just says "Syntax Error"
 

anishkgt

Registered User.
Local time
Today, 15:15
Joined
Nov 4, 2013
Messages
384
The open field is number so that i could write it 0 or 1. If its Yes or NO it would be a check box so let it as number.
 

anishkgt

Registered User.
Local time
Today, 15:15
Joined
Nov 4, 2013
Messages
384
Here is the complete macro
 

Attachments

  • Capture.PNG
    Capture.PNG
    9.5 KB · Views: 283

Minty

AWF VIP
Local time
Today, 13:15
Joined
Jul 26, 2013
Messages
10,367
You aren't comparing the result of the dlookup to anything.
It should be
Code:
If DLookUp("LockNum","tblImportLock","[Open]=1")[COLOR="Red"] = 1 [/COLOR]Then
 

CJ_London

Super Moderator
Staff member
Local time
Today, 13:15
Joined
Feb 19, 2013
Messages
16,601
general point if you are not returning a value for a field to use (as you are here - you just want to know if a record exists), use DCount

if DCount("*","tblImportLock","[Open]=1")<>0 then

Not sure what your logic is supposed to be but if the only options are 0 or 1 then your ElseIf only needs to be an Else - otherwise you are interrogating the data twice

Finally, recommend you learn VBA and don't use macros - they are limited in functionality and as you have discovered, the error messages can be vague
 

anishkgt

Registered User.
Local time
Today, 15:15
Joined
Nov 4, 2013
Messages
384
I get the same error over and over again " Syntax Error"
 

Minty

AWF VIP
Local time
Today, 13:15
Joined
Jul 26, 2013
Messages
10,367
So what is your code now - we can't guess I'm afraid.
Please show us what you have now.
 

anishkgt

Registered User.
Local time
Today, 15:15
Joined
Nov 4, 2013
Messages
384
Attached here is the complete code to uploading data from a text file into a database
 

Attachments

  • code.txt
    28.9 KB · Views: 83

CJ_London

Super Moderator
Staff member
Local time
Today, 13:15
Joined
Feb 19, 2013
Messages
16,601
so you expect us to scroll through hundreds of lines of text with no idea where to look for a syntax error and no documentation of what the code is doing? I see no use of dlookup or dcount in your code.

Syntax errors occur when you are writing the code so you should know exactly on what line the error occurs

All I can say is it seems a very complicated way of importing data. I would have thought it could be accomplished with a few lines of sql.

Perhaps explain what you are trying to do, provide some example data and the outcome required from that data.
 

anishkgt

Registered User.
Local time
Today, 15:15
Joined
Nov 4, 2013
Messages
384
Sorry ! i thought it would be obvious as it was mentioned in the previous posts.
the line
Code:
If DCount("FileID", "qryMIR", "[MIRSeq]=" & MIRSeq & " and [TicketNumber]=""" & tkt & """") Then 'validate MIR Sequence number and Ticketnumber to avoid Duplication
throws an error.


A sample file to read is attached which is read and imported into access database. The line with the systax error checks a query for repeating MIRSeq number and Ticket number.

The thread discussing about the code is here
 

Attachments

  • AOTREGAL.txt
    734 bytes · Views: 57

CJ_London

Super Moderator
Staff member
Local time
Today, 13:15
Joined
Feb 19, 2013
Messages
16,601
this has already been answered - see post #6. Same applies, you need

if dcount(…….)=0 then

or perhaps <>0, depends on what you want the code to do
 

isladogs

MVP / VIP
Local time
Today, 13:15
Joined
Jan 14, 2017
Messages
18,207
The thread you linked has 320 posts. Also far too many to check although you were involved at the end.
Not sure what the new text file is meant to show without spending time reading that thread.
Please help us to help you.

In your DCount, as well as adding >0 or similar, is MIRSeq a number field and TicketNumber a text field (despite it's name)? If not you will get errors
 

anishkgt

Registered User.
Local time
Today, 15:15
Joined
Nov 4, 2013
Messages
384
MIRSeq is a number and TicketNumber is a short text
 

anishkgt

Registered User.
Local time
Today, 15:15
Joined
Nov 4, 2013
Messages
384
So i just copied the same access file on my work desktop and there it seems to work without a problem.....No syntax error.
 

Users who are viewing this thread

Top Bottom