Question : global variable username passthrough sql to generate a users work orders.

let me give you my code examples
my module

Global GvarID As String
Global GloginEmp As String
Public lngMyEmpID As Long

my login

Private Sub cmdLogin_Click()
  If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value) Then

        lngMyEmpID = Me.cboEmployee.Value
        GloginEmp = DLookup("EmployeeName", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value)
        GvarID = Me.cboEmployee.Value
       
        DoCmd.Close acForm, "frmLogon", acSaveNo
        DoCmd.OpenForm "Water Dome Menu"

        Else
        MsgBox "Password Invalid.  Please Try Again", vbOKOnly, "Invalid Entry!"
        Me.txtPassword.SetFocus
    End If
   
'If User Enters incorrect password 3 times database will shutdown
   
    intLogonAttempts = intLogonAttempts + 1
    If intLogonAttempts > 3 Then
        MsgBox "You do not have access to this database.  Please contact your system administrator.", vbCritical, "Restricted Access!"
        Application.Quit
    End If
   
End Sub

and my sql statement

SELECT *
FROM WorkOrders LEFT JOIN (SELECT [tblEmployees].[lngEmpID], [tblEmployees].[EmployeeName] FROM tblEmployees ORDER BY [EmployeeName])  AS Lookup_Mechanic ON WorkOrders.Mechanic = Lookup_Mechanic.lngEmpID
"WHERE (((Lookup_Mechanic.EmployeeName)=" & GloginEmp _ & "

basically i am wanting when you open a form based on the sql above for the records to only display the current mechanic logged in , and i keep getting sytanx errors. I know its probably somthing simple im just over looking.



Answer : global variable username passthrough sql to generate a users work orders.

If you are building the sql statement in code then your punctuation around the Where clause has gone awry.

And the left join will not operate as a left join because of the selection, it will operate as an inner join.
But I think it's an inner join you really want here.

strsql= "SELECT * FROM WorkOrders INNER JOIN (SELECT [tblEmployees].[lngEmpID], [tblEmployees].[EmployeeName] FROM tblEmployees ORDER BY [EmployeeName])  AS Lookup_Mechanic ON WorkOrders.Mechanic = Lookup_Mechanic.lngEmpID WHERE Lookup_Mechanic.EmployeeName='" & GloginEmp & "'"

I notice that you are using both Global and Public in your definitions.
Global is dead (but still works). Public is current usage.
Random Solutions  
 
programming4us programming4us