How to make a text box to perform as a combo/list box (1 Viewer)

machinetech

New member
Local time
Today, 03:03
Joined
Jun 10, 2019
Messages
7
I want to have a text box that auto-populates with a value its pulling from a query. I could do this with a combo box and have the record source using the dlookup function. However I do not want the user to have to select this value from the combo box.

However I still need the value to be saved to the control source. Currently I have the control source of the text box filled with the dlookup function, and it is retrieving the correct value, I now just need a way to have this value saved to the field I need it to be saved to when I save the record.
 

Micron

AWF VIP
Local time
Today, 04:03
Joined
Oct 20, 2018
Messages
3,478
Never mind - I focused too much on the post title.


However I do not want the user to have to select this value from the combo box.
BTW, you can have the value in a combo row without the user even seeing it and get it from there - if you can make the value part of the row source.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 04:03
Joined
May 21, 2018
Messages
8,516
However I still need the value to be saved to the control source. Currently I have the control source of the text box filled with the dlookup function, and it is retrieving the correct value, I now just need a way to have this value saved to the field I need it to be saved to when I save the record

If I understand this correctly, then simply do this in the forms on current event instead of the controls recordsource. Bind the control to the correct recordsource. In the forms on current event something like

Code:
if isnull(me.someTextbox) then
  me.someTextbox = yourDlookupFormula
end if
 

machinetech

New member
Local time
Today, 03:03
Joined
Jun 10, 2019
Messages
7
If I understand this correctly, then simply do this in the forms on current event instead of the controls recordsource. Bind the control to the correct recordsource. In the forms on current event something like

Code:
if isnull(me.someTextbox) then
  me.someTextbox = yourDlookupFormula
end if

This is essentially what I did.
In the "On Change" Event Procedure for the preceeding combo box, I put in a dlookup function that looked like this:

Code:
Private Sub Combo1_Change()
     Text1 = Dlookup("[Field]", "Query")
End Sub

So this controls the input into the textbox, while I can still have the control source to the field the form is tied to.

Essentially a text box with a control source, that acts like a combo/list box with a row source.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 01:03
Joined
Aug 30, 2003
Messages
36,131
I would use the after update event; the change event fires with every keystroke.
 

Users who are viewing this thread

Top Bottom