Page 2 of 2 FirstFirst 12
Results 16 to 21 of 21
  1. #16
    hammer187 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Aug 2012
    Posts
    66
    EmployeeID is numeric.

  2. #17
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Code:
    Private Sub Command19_Click()
    Dim rs as DAO.RecordSet
    dim txtID 
    dim txtName
    
    txtID = Forms![LoginForm2]![txtEmployeeID]
    txtName = Forms![LoginForm2]![Text13]
    
    Set rs = CurrentDb.OpenRecordset("SELECT * FROM CoachTable WHERE EmployeeID = " & txtID, dbOpenDynaset)
    
    If rs.EOF Then
        txtName = DLookup("CoachName", "HourlyTable", "EmployeeID= " & txtID)
        Forms![LoginForm2]![Text13].SetFocus
        Forms![LoginForm2]![Text13] = txtName
    Else
        txtName = DLookup("CoachName", "CoachTable", "EmployeeID= " & txtID)
        Forms![LoginForm2]![Text13].SetFocus
        Forms![LoginForm2]![Text13] = txtName
    End If
    End Sub
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #18
    hammer187 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Aug 2012
    Posts
    66
    Somehow my if statement is always true no matter what. That is why it is not going into the else statement.

  4. #19
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    OK now we know that EmployeeID is actually a text field, try:
    Code:
    Private Sub Command19_Click()
    Dim rs as DAO.RecordSet
    Dim txtID 
    Dim txtName
    
    txtID = Forms![LoginForm2]![txtEmployeeID]
    txtName = Forms![LoginForm2]![Text13]
    
    Set rs = CurrentDb.OpenRecordset("SELECT * FROM CoachTable WHERE EmployeeID = '" & txtID & "'", dbOpenDynaset)
    
    If rs.EOF Then
        txtName = DLookup("CoachName", "HourlyTable", "EmployeeID= '" & txtID & "'")
        Forms![LoginForm2]![Text13].SetFocus
        Forms![LoginForm2]![Text13] = txtName
    Else
        txtName = DLookup("CoachName", "CoachTable", "EmployeeID= '" & txtID & "'")
        Forms![LoginForm2]![Text13].SetFocus
        Forms![LoginForm2]![Text13] = txtName
    End If
    End Sub
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #20
    hammer187 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Aug 2012
    Posts
    66
    That worked. What did you change?

  6. #21
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    I put the single quote marks back into the code because EmployeeID is actually a text field. If it was a number field (integer, long, single, double) they would not be needed. If EmployeeID had been numeric then you would need to remove the single quotes.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. if statement in sql statement, query builder
    By 54.69.6d.20 in forum Access
    Replies: 4
    Last Post: 09-11-2012, 07:38 AM
  2. Query any part of the field
    By spleewars in forum Queries
    Replies: 1
    Last Post: 05-31-2012, 07:13 PM
  3. Replies: 7
    Last Post: 08-17-2011, 01:49 PM
  4. Replies: 3
    Last Post: 06-23-2011, 07:39 PM
  5. WHERE as part of JOIN not after
    By thestappa in forum Queries
    Replies: 1
    Last Post: 05-14-2010, 10:52 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
  •  
Other Forums: Microsoft Office Forums