Consulting

Results 1 to 4 of 4

Thread: Display a value in a textbox

  1. #1
    VBAX Regular
    Joined
    May 2015
    Posts
    87
    Location

    Display a value in a textbox

    On a form I built in micorsoft access, while in design mode if i place the following code into the control source on the data tab for the textbox it displays the result I want but only after I close and reopen the form.
    =DLookUp("[FORWRD_NAME]","File_No","[FILE_NO] = Form![FileNo]")

    Is there a way to have this automatically display when I enter the file number into the FileNo textbox on the form?

    Or way to update the textbox with the result by coding a command button?

    I'd actually prefer to have the control source set to a field in a table to pass the value of this result but I can't find a way to display the result without using the control source.

    Thank you for any help

  2. #2
    VBAX Expert
    Joined
    Oct 2012
    Posts
    726
    Location
    Try requery (or maybe refresh) in the after update event.

    Private Sub Text1_AfterUpdate()
        Text2.requery
    End Sub

  3. #3
    VBAX Regular
    Joined
    May 2015
    Posts
    87
    Location
    This didn't work im wondering if I can do something like this...... I have a text box called FileNo. Im wondering if I can use an on enter event so when the user enters a file number in the FileNo textbox and clicks enter it will display the result of the dlookup statement below in the txtForwarder text box. I set up this code which isn't displaying the result..... so not sure where to go from here. My program is working from beginning to end but if I could remove some of the manual work for the user using this method or something similar it would save them a lot of time.

    Private Sub FileNo_Enter()
    Me.txtForwarder = DLookup("[FORWRD_NAME]", "File_No", "[FILE_NO] =
    Form![FileNo]")
    End Sub

  4. #4
    VBAX Expert
    Joined
    Oct 2012
    Posts
    726
    Location
    Your dlookup isn't right.

    DLookup («expr», «domain», «criteria»)

    «expr» : the table field you want to return
    «domain» : table
    «criteria» : where clause - somefield = somevalue

    =DLookUp("[FORWRD_NAME]","File_No","[FILE_NO] = Form![FileNo]")
    should be (assuming File_No is text, if not remove the single quotes)

    =DLookUp("[FORWRD_NAME]","File_No","[FILE_NO] = '" & [Forms]![File_No]![File_No] & "'")
    also assuming you have a table called File_No containing a field called File_No and you're getting a value from a control called File_No on a form called File_No.

Posting Permissions

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