Query returns an error

mveijndh

Registered User.
Local time
Today, 07:49
Joined
Dec 17, 2011
Messages
113
Below the lines of code I'd put in to find default settings after opening a database.

Public strWindowUser As String
strWindowUser = Environ("username")
strSQL1 = "SELECT tblDefault.DefaultID, tblDefault.DefaultUserId, tblDefault.DefaultDate, tblDefault.DefaultCur, tblDefault.DefaultCountry, " & _
" tblDefault.DefaultLabourCosts, tblDefault.DefaultPartMult, tblDefault.DefaultFileFolder, tblDefault.DefaultAccountingEmail, tblDefault.DefaultWindowUserName " & _
"FROM tblDefault " & _
"WHERE tblDefault.DefaultWindowUserName=" & strWindowUser & ";"

The error is in de & strWindowUser. This is put in as a field in the where clause. What am I missing??
 
The problem is that the username is in general a string.
In SQL that needs to be between single quotes.
So what you need to do is use this :
Code:
"WHERE tblDefault.DefaultWindowUserName='" & strWindowUser & "';"
 
@Grumm,

Thanks!! it was as simple as that. good lesson for the future!!
 

Users who are viewing this thread

Back
Top Bottom