Run-time error '3075' (syntax error- missing operator)

KoskeKos

New member
Local time
Today, 21:53
Joined
May 4, 2021
Messages
28
Hello 2 Everyone!

I have problem with first line of code (syntax error- missing operator) and can't figure it out:
1645713513242.png

Here is code:
Code:
If DLookup("[HasAccess]", "tUserAccess", "[UserAccessID]= " & TempVars("UserType") & " AND [FormName]='" & Me.Name & "'") = False Then
      DoCmd.Close acForm, Me.Name
      MsgBox "You dont have access!"
   End If

What i cant see?
 
try this
"[UserAccessID] = " & TempVars("UserType") & " AND [FormName] = " & Chr(34) & Me.Name & chr(34) )

is the tempvars a string or a number? - your code works for a number, and would fail with a null
I would add spaces before and after the "=" signs
I use chr(34) rather than messing with dble quotes.

I imagine there's a problem in this somewhere.

maybe wrap it an nz to return false if the dlookup fails.

nz(DLookup("[HasAccess]", "tUserAccess", "[UserAccessID]= " & nz(TempVars("UserType"),0) & " AND [FormName] = " & chr(34) & Me.Name & chr(34)) ,false) = False
 
I have problem with first line of code (syntax error- missing operator) and can't figure it out:
Code:
dim s1
s1= DLookup("[HasAccess]", _
 "tUserAccess", _
 "[UserAccessID]= " & TempVars("UserType") & " AND [FormName]='" & Me.Name & "'")
if isnull(s1) or s1=false then
MsgBox "You dont have access! "
DoCmd.Close acForm, Me.Name
End If
 
try this
"[UserAccessID] = " & TempVars("UserType") & " AND [FormName] = " & Chr(34) & Me.Name & chr(34) )

is the tempvars a string or a number? - your code works for a number, and would fail with a null
I would add spaces before and after the "=" signs
I use chr(34) rather than messing with dble quotes.

I imagine there's a problem in this somewhere.

maybe wrap it an nz to return false if the dlookup fails.

nz(DLookup("[HasAccess]", "tUserAccess", "[UserAccessID]= " & nz(TempVars("UserType"),0) & " AND [FormName] = " & chr(34) & Me.Name & chr(34)) ,false) = False
Thnx for answer.
Tempvars is number and when checking with msgbox it shows a number.
Ill check.
 
I tend to put the criteria into a variable if more than one item, then debug.print it to see what I have.
You can also then post the content here if you still cannot see the problem.?
Once correct, use that in the domain function as well.
 
what do you mean by Me.Name, are you referring to the Name property of the form?
or you have a control named Name?

what you are doing there is getting the Name of the Form.
you need to enclosed in bracket (Me![Name]) if you are referring to control, or better
rename the control to something else like txtName.
 
Just to say i figured it out. My mistake. (How strange is that :eek:?!?!).
Data types of IDs weren't the same in two tables.
Anyway thank you all. 🍻
 

Users who are viewing this thread

Back
Top Bottom