Results 1 to 2 of 2

Thread: Form Query

  1. #1
    Join Date
    Apr 2002

    Unanswered: Form Query

    I have a form that has two textbox: ID and Name

    I also have a query that has ID and Name

    What I wanna do is when user changes ID textbox, the Name textbox is updated. I am aware that we can put Forms("MyForm").ID in the ID's criteria in the query. What I am not sure is how to transfer the Name value in the query to the Name textbox.


  2. #2
    Join Date
    Mar 2002
    Try the following for the On Exit Property of the ID field:

    Dim db As Database
    Dim recNamess As Recordset
    Dim strSQL As String

    strSQL = "SELECT ID FROM tblNames WHERE emplid = '" & Me![Field_ID].Value & "'"

    Set db = CurrentDb
    Set recNames = db.OpenRecordset(strSQL, dbOpenDynaset)

    If recNames.RecordCount > 0 Then
    Me![Field_Name].Value = recNames("ID").Value
    Me![Field_Name].Value = ""
    End If

    This procedure should do the trick, I have used it before.
    You can adjust the SQL String to mirror the SQL statement in your Query. There is a way to Create a recordset directly from the query, but I think that is redundant, and I personally find it easier to work directly with SQL statements in the procedures

    Good luck

Posting Permissions

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