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

KoskeKos

New member
Local time
Today, 21:51
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?
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 20:51
Joined
Sep 12, 2006
Messages
15,658
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
 

SHANEMAC51

Active member
Local time
Today, 22:51
Joined
Jan 28, 2022
Messages
310
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
 

KoskeKos

New member
Local time
Today, 21:51
Joined
May 4, 2021
Messages
28
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.
 

Gasman

Enthusiastic Amateur
Local time
Today, 20:51
Joined
Sep 21, 2011
Messages
14,310
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.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:51
Joined
May 7, 2009
Messages
19,245
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.
 

KoskeKos

New member
Local time
Today, 21:51
Joined
May 4, 2021
Messages
28
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

Top Bottom