Populate textbox with a field from another combo box's row/source table

Bada bing!

Registered User.
Local time
Yesterday, 23:51
Joined
Jul 13, 2005
Messages
15
I've designed a data entry form based on a table. I use a few combo boxes, (linked via SQL statements for their row/source) to fill most of the fields in the table.

What I want to do is populate one textbox on the form with the contents of a field in one of the combo box's row/source tables. The field I want isn't shown in the combo box.

Basically, what I want is that when I choose a PART NUMBER from a combo box, I want the OEM_ID from the same table to jump into the textbox below it.

I think I may have tied myself in knots though to the point where what I want can't be done. Any ideas? I know this is probably going to take a couple of goes at explaining. :P
 
Last edited:
Definitely doable.

In the afterupdate event of your combobox, you'll need to put a code
that goes something like this:

Me.textboxname.value = Me.comboboxname.column(1)

With the above code, you're basically assigning the value of
field 2 of your combobox recordsource to that of the target textbox.

Note that the index value of (1) represents field no. two in your recordsource.
That's because the index values start with (0) not (1); therefore field 2 would have an index value of (1).

Needless to say, the value you're trying to capture must appear in one of the
fields of your combobox recordsource.

Hope this helps.
 
Bb,

You can use the Combo's AfterUpdate event to do a DLookup and
populate the text box.

Wayne
 
Thanks for the info guys, I'll try tonight when I get home. :)
 
edtab said:
In the afterupdate event of your combobox, you'll need to put a code
that goes something like this:

Me.textboxname.value = Me.comboboxname.column(1)

With the above code, you're basically assigning the value of
field 2 of your combobox recordsource to that of the target textbox.

Note that the index value of (1) represents field no. two in your recordsource.
That's because the index values start with (0) not (1); therefore field 2 would have an index value of (1).
This worked a treat, thanks again mate.
 
how would i do the same thing but from 2 different forms?

i have a login form and i want the username from there to transfer to a second form.

thanks a million!
 
There are a few really easy ways to do that.

1) Make the Username variable a global variable in a module. Then it's available to any other module and/or form. At the top of a module (After Option Compare and Option Explicit, but before the first subroutine or function), put this:

Global Username As String

Note that has to be in a module. If you make it global in a form, then it's accessible to every subroutine or function in that form, but not other areas. In a module, it has true global scope, where in a form, the scope is limited to the form.

2) Connect the login form to a table and link the field "UserName" to the textbox. Then, reference that table from any number of forms. For example, make a table called "t_Login" and place a field called UserName in it. Make that the control source for the UserName textbox on the login form. From any other form, you could do this:

UserName = DLookup("[UserName]","t_Login")

Either way will work. The second option allows you to "remember" the last login name, as it were.

~Moniker
 
Last edited:
You could also hide the login form as opposed to closing it. Its controls and their values are then available to you in other forms without the form being visible.
 
thanks for the help.

i just want to get the username that they typed into the login box (different than the network login) on one form to populate a username on another form.

i'm sure there is some simple code i could use to make that happen, right?

Rob
 
Try this:

In the after update of the login textbox :

forms!tagetFormName!loginTextboxName = forms!sourceFormName!loginTextboxName

Note: This would only work if both forms are available in memory,
ie. you have both of them loaded.

This approach would not test the validity of the username typed in,
you'll have to additional coding for that.
 
yeah, i get a runtime error. thanks though.

i have the login form as the first form the user encounters, then when they click on the enter button (after the name and pass are validated) it loads up the second form. it's on the second form that i want the username from the first form to be automatically entered in the textbox.
 
duh, i had some code switced around.

i just put the code you gave me in the 'on open' for the new form, works like a charm!

thanks a million!
 

Users who are viewing this thread

Back
Top Bottom