Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo Box to Insert 2 Fields Via Form

Status
Not open for further replies.

spock2054

IS-IT--Management
Feb 12, 2002
48
US
Hi,

I have a table with 2 fields in it, Name and Class, that I would like to insert into a main table, into 2 seperate fields , [Employee_Name] and [Trade_W/C_Code] via a form by selecting the Name field in a combo box displaying both Name and Class.

I entered the following code:

Private Sub Combo49_AfterUpdate()
Name = DLookup("[Name]", "tblName", "[Employee_Name]='" & MyCombo & "'")
Class = DLookup("[Class]", "tblName", "[Trade_W/C_Code]='" & MyCombo & "'")
End Sub


It cannot find my table named Name so I can't tell if it's working or not.

Any assistance would be appreciated.

RJ
 
I think your problem is in DLookup.

What exactly is MyCombo? Does tblName contain both Name and Employee_Name?

I think what you're looking for is
dlookup("Name","tblName", "Name='" & Combo49.Column(0) & "'")

or

dlookup("Employee_Name","tblName","Employee_Name='" & Combo49.Column(0) & "'")
 
RJ

"Name" is a reserved word. Consider using a different "name".

The other problem is the name of the combo box...

Code:
Private Sub [COLOR=blue]Combo49[/color]_AfterUpdate()
UseAnotherName = DLookup("[Name]", "tblName", "[Employee_Name]='" & [COLOR=blue]Me.Combo49[/color] & "'")
Class = DLookup("[Class]", "tblName", "[Trade_W/C_Code]='" & [COLOR=blue]Me.Combo49[/color] & "'")
End Sub
 
Is your combo box working correctly? If so, the following code should work

Code:
Private Sub Combo49_AfterUpdate()
    Me.Name = Me.Combo49.Column(0)
    Me.Class = Me.Combo49.Column(1)
End Sub

As Willir suggested, I would also change the table and field names away from Access Reserved keywords to avoid problems.

HTH
Lightning
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top