combo box

  • Thread starter He cries for help
  • Start date
H

He cries for help

I have a form with 3 text boxes named contact, telephone and fax,

I want to create a combo box to select a field named 'supplier' with the
data taken from a table named "supinfo". the table has four columns named
supplier, contact, telephone, and fax.

When selecting a single supplier from the supplier column of the table i
woulld like data also to be automatically entered into the text boxes named
above from the columns of the table named "supinfo". I am a novice at
database progranning so please keep
your answer as definitive as possible. Thanks I have really stressed over
this problem.
 
W

Wayne-I-M

Hi

Try this.
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.
_______________________________________
There is another way you can do this
In the “ControlSource†Row of the “Date†column of each text box you can put
=[cboDetails].column(1)
Or 2 or 3 depending on which bit of data you want displayed – but the code
will work better.

Good luck – Hope this helps
 
W

Wayne-I-M

ooops - after all that I forgot to give you the small bit of code you need -
sorry


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

He cries for help

Wayne, this works great except for one thing, when I close the form all the
prevous records are changed to the most recently entered value. Can the code
be modified to save the information to the current record only and be blank
upon entry into a new record?
 

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