dual purpose combo box

S

SandyR

I have a form with a recordsource query that includes data items from my main
table and from my vendor table. This is a display only form. I want the
user to be able to select the record to look at based on primary key (no
problem there) or on vendor name.

To do this, I set up the field txtselvendor as an unbound combobox. The
rowsource is a query retrieving all records with the selected vendor. Once
the user selects the record he or she wants to look at, I want the record to
display and the vendor field to show the vendor name, which shouldn't be a
problem because it is in the recordsource query for the form. The correct
record displays in the form, but so far I haven't succeeded in getting the
vendor name to appear. I also need it to update when I move to next or
previous record.

Any suggestions would be much appreciated!

Here is the form recordsource query:

SELECT tblprmain.pr_no, tblprmain.vendor_number, tblprmain.request_date,
tblprmain.department, tblprmain.ship_to_address, tblprmain.date_required,
tblprmain.shipping, tblprmain.submitter, tblprmain.status,
tblprmain.dont_send_to_vendor, tblprmain.INSTRUCTIONS, Vendor.VENDOR,
Vendor.[1ADDR], Vendor.[2ADDR], Vendor.[3ADDR], Vendor.[4ADDR], Vendor.ZIP,
Vendor.[4ZIP], tblprmain.SUMMARY FROM tblprmain INNER JOIN Vendor ON
tblprmain.vendor_number = Vendor.VEND_NO ORDER BY tblprmain.pr_no;

Here is the query for the txtselvendor field. This field is a combo box
with four columns:

SELECT [qryListVendorName].[VENDOR], [qryListVendorName].[VEND_NO],
[qryListVendorName].[pr_no], [qryListVendorName].[SUMMARY] FROM
[qryListVendorName]

Here is the after_update code for the combo box:

Private Sub txtselvendor_AfterUpdate()
' Author : rosensan
' Purpose : fill in the vendor address fields from the combo box query
'---------------------------------------------------------------------------------------
'
Dim cbo As ComboBox
Dim rs As Recordset
On Error GoTo vendor_AfterUpdate_Error

Set cbo = Me.txtselvendor

Me.txtselectpr_no = cbo.Column(2)
Set rs = Me.Recordset.Clone
rs.FindFirst "[PR_NO] = " & Str(Me!txtselectpr_no)
Me.Bookmark = rs.Bookmark

Set cbo = Nothing


vendor_AfterUpdate_exit:
On Error GoTo 0
Exit Sub

vendor_AfterUpdate_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
txtselvendor_AfterUpdate of VBA Document Form_tblprmain1"
Resume vendor_AfterUpdate_exit

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top