PDA

View Full Version : Display a value in a textbox



cleteh
06-07-2015, 11:32 PM
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

jonh
06-08-2015, 01:32 AM
Try requery (or maybe refresh) in the after update event.


Private Sub Text1_AfterUpdate()
Text2.requery
End Sub

cleteh
06-08-2015, 01:47 PM
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

jonh
06-09-2015, 01:42 AM
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.