Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invalid Syntax when opening form 1

Status
Not open for further replies.

SQLScholar

Programmer
Aug 21, 2002
2,127
0
0
GB
Hi all,

I have this code in a form (generated by access)

Code:
    Dim stDocName As String
    Dim stLinkCriteria As String
    

    stDocName = "FrmUserOverides"
    
    stLinkCriteria = "[ADLogon]=" & Me![ADLogon]
    DoCmd.OpenForm stDocName, , , stLinkCriteria

Which should all be fine.... however.....

ADLogon is in this format DOMAIN\USER. So i am getting an error which looks something like this "Incorrect syntax near '\'."

So how do i get round this? The tables need the DOMAIN\ in them. Both the forms are based on tables with the DOMAIN\ on the ADlogon.

Any ideas how to get round this?

TIA

Dan

----------------------------------------

Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind - Bernard Baruch

Computer Science is no more about computers than astronomy is about telescopes - EW Dijkstra
----------------------------------------
 
Missing quotes.

Code:
Dim stDocName As String
    Dim stLinkCriteria As String
    

    stDocName = "FrmUserOverides"
    
    stLinkCriteria = "[ADLogon]=" & [highlight #FCE94F]Chr(34)[/highlight] & Me![ADLogon] & [highlight #FCE94F]Chr(34)[/highlight]
    DoCmd.OpenForm stDocName, , , stLinkCriteria

That is telling VBA to use the ASCII character, 34, which is the quotation mark. You can specify the quotes inside of quotes sort of thing as well, so you could use """ isntead of Chr(34) if you want. If 3 quotes doesn't work, try 4 - I think it's 3 in this case, but I often forget - call me crazy, but I remember Chr(34) more readily.

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57
 
Ahhh.... I think i have sussed it.

I am using Access data projects conencting to SQL - so Chr(34) actually had to be Chr(39)

Thanks for your help!

Dan


----------------------------------------

Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind - Bernard Baruch

Computer Science is no more about computers than astronomy is about telescopes - EW Dijkstra
----------------------------------------
 
In fact:
Code:
stLinkCriteria = "ADLogon='" & Me!ADLogon & "'"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Yep, it's single quotes for ODBC connections, generally, and double for Access.

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57
 
and double for Access
Sorry to disagree, but even JetSQL is happy with single quotes ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I guess in some circumstances, but not all. From what I remember and understand, there are some places where you can use single quotes, and sometimes double. Are there any circumstances where either works just as well?

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top