Results 1 to 2 of 2

Thread: Access '97 Form

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Posts
    24

    Question

    Here's the deal. I want to be able to key an employee number into a form and have the employee's name and dept. # inserted from another table. Other productivity info will also be keyed into the form. I just can't figure out how to get the employees' name and dept # automatically dropped into the form based on the employee number that is entered.

    Any suggestions would be appreciated.

    Thanks,
    ern

  2. #2
    Hyperactive Member
    Join Date
    Oct 2000
    Posts
    400
    Off the top of my head:

    Code:
    Private Sub txtEmpNo_AfterUpdate()
        Dim db As Database
        Dim rst As Recordset
    
        Set db = CurrentDb
        Set rst = db.OpenRecordset("SELECT * FROM OtherTable WHERE EmpNo = " & Me.txtEmpNo & ";",dbOpenSnapshot)
    
        If rst.EOF Then
            MsgBox "Employee #" & Me.txtEmpNo & " not found.", vbInformation, "Notice"
            Exit Sub
        End If
     
        Me.txtDeptNo = rst!DeptNo
        Me.txtEmpName = rst!EmpName
    
        rst.Close
        Set rst = Nothing
    End Sub

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