Results 1 to 4 of 4

Thread: Syntax error in Access 2007 query

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2017
    Posts
    8

    Syntax error in Access 2007 query

    Hello everyone. I need help troubleshooting a query error. There is a form where if a user selects an Employee Id from a Combobox, the Label Below automatically displays the Employee Name.

    Here is the query,

    Code:
    rs.Open "SELECT tblEmp.EM_ID, tblEmp.NAME FROM tblEmp where tblEmp.EM_ID = " & Me.cboEmpId.Text & " ;", cn, adOpenKeyset, adLockPessimistic
    But, Due to some reasons, It's not working.

    Codes,

    Code:
    Private Sub cboEmpId_Change()
    If Me.cboEmpId.Text = vbNullString Then Exit Sub
    If rs.State = adStateOpen Then rs.Close
    rs.Open "SELECT tblEmp.EM_ID, tblEmp.NAME FROM tblEmp where tblEmp.EM_ID = " & Me.cboEmpId.Text & " ;", cn, adOpenKeyset, adLockPessimistic
    Do While rs.EOF = False
    Me.lblName.Caption = rs.Fields("NAME")
    rs.MoveNext
    Loop
    Exit Sub
    Set rs = Nothing
    End Sub
    Thanks in advance!
    Last edited by sanjit.sam; Dec 3rd, 2017 at 01:19 AM.

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width