code will and won't work

H

He cries for help

I have four fields on my database form they are: Supplier, contact,
telephone, fax.
I am trying to enter the suppliers name from a combo box and auto fill the
balance of the fields using test boxes. I have used followed the following
advice and it worked, with the exception that it changes all the previous
records to the current selection of supplier in a new record.

Open your form in design view.
Select "View" -> "Toolbox"
Select the "Combo Box" icon
Click the form where you want your new combo box
Select -> Lookup up items in a table
Select your table from the list
Select the primary field plus the 3 fields contact, telephone and fax
Follw the wizard through to the end nd select finish
On the Toolbox select the "Textbox" icon
Click the form 3 times where you want the 3 boxes to go (you can move them
later)
Select the st textbox
Right clic and open the properties box
Select the "Other" colum
Select the "Name" row
Name the text box txtContact
Name the 2nd box txtTelephone
Name the 3rd box txtFax
Select the combo and name it cboDetails
Save the form

Select the combo box (cboDetails)
Make sure the properties box is open
Select the "Event" column
Select the "AfteUpdate" row
Select the build option (...)
Select code builder
You will see this

Private Sub cob_details_AfterUpdate()

End Sub

You need to add some code between these 2 lines to tell your application
what you want it to do "After Update". Basically you want the content of the
2nd 3rd and 4th column in the combo to become the value shown in the text
boxes. So you need to add a small bit of code so that t looks like this.

Private Sub cbodetails_AfterUpdate()
Me.txtContact = Me.cbodetails.Column(1)
Me.txtTelephone = Me.cbodetails.Column(2)
Me.txtFax = Me.cbodetails.Column(3)
End Sub

Any Ideas????
_______________________________________
 
A

Arvin Meyer [MVP]

The procedure works fine for single form view, but cannot be used in a
datasheet or continuous form. You will need to use a query and bind your
textboxes to the columns in the query. Use an the ID from the many side, and
an Outer join in the query (an Outer join that uses all the records from the
many side, and 1 record from the 1 side. This is sometimes called an
auto-lookup query. You will no longer need your code. Also, you will still
not need to store the data from the previous unbound controls.
 

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