Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2013

    Unanswered: Whats Wrong With My Code?

    Private Sub Form_Load()

    Dim rst As DAO.Recordset
    Dim rst1 As DAO.Recordset
    Dim rst2 As DAO.Recordset
    Dim rst3 As DAO.Recordset

    ' Set the variables to the current database in use and tables
    Set db = CurrentDb()
    Set rst = db.OpenRecordset("NRCEmployees")
    Set rst1 = db.OpenRecordset("T_EMPLOYEE")
    Set rst2 = db.OpenRecordset("T_EMPLOYEE_INFO")

    Dim strMsg As String
    Dim strLANID As String
    Dim strSQL As String

    strMsg = "Enter Employee's LanID"
    strLANID = InputBox(Prompt:=strMsg)
    Debug.Print strLANID
    With rst1
    strSQL = "SELECT LanID from T_EMPLOYEE where LanID = !Me.strLANID"
    Debug.Print strSQL
    DoCmd****nSQL strSQL
    If Not .NoMatch Then 'we found the record
    MsgBox "We found the record"
    !Me.UserID = LanID
    End If
    End With

    The Error Message Says A RunSQL action requires an arguement consisting of an SQL statement

  2. #2
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    in short
    you are not supplying valid SQL
    strSQL = "SELECT LanID from T_EMPLOYEE where LanID = !Me.strLANID"
    specifically !Me.strLANID"
    what I think you are trying to do is pull a value from a form or variable in which case
    strSQL = "SELECT LanID from T_EMPLOYEE where LanID = " & strLANID
    that assumes that strLANID is a number, event though by convention I'd expect a varaiable prefixed by str to be of type string

    if strLANID is a string then it shoudl be quoted
    strSQL = "SELECT LanID from T_EMPLOYEE where LanID = '" & strLANID & "'"
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts