views:

231

answers:

2

Hi all, hopefully somebody can help

The table structure is as follows:

tblCompany:   
compID
compName

tblOffice:  
offID,
compID,   
add1, add2, add3 etc...

tblEmployee:   
empID
Name, telNo, etc...   
offID

I have a form that contains contact details for employees, all works ok using after update. A cascading combo box, cmbComp, allows me to select a company, and inturn select the appropriate office, cboOff, and updates the corresponding tblEmployee.offID field correctly. Fields are automatically updated for the address also

cmbComp: RowSource

SELECT DISTINCT tblOffice.compID, tblCompany.compID 
FROM tblCompany 
INNER JOIN AdjusterCompanyOffice 
ON tblCompany.compID=tblOffice.compID 
ORDER BY tblCompany.compName; 

cboOff: RowSource

SELECT tblCompany.offID, tblCompany.Address1, 
tblCompany.Address2, tblCompany.Address3, tblCompany.Address4, 
tblCompany.Address5 
FROM tblCompany 
ORDER BY tblCompany.Address1; 

The problem I am having is that when i load a new record how to retrieve the data and automatically load the cmbComp and text fields.

The cboOff combo box loads correctly as the control source for this is the offID

I imagine there must be a way of setting the value on opening the record? Not sure how though. I dont think I can set the controlsource cmbComp or text fields, or can I?

Any help/point in the right direction appreciated, have been searching for a way to do this but cant get anywhere!

-edit

Ive tried adding the following for the control of a text field

=[Forms]![frmAdjPersonalDetails]![cboAdjOff].[Column](2)

This works at getting the values but causes an error with the after Update used to create the cascading combo box and update the text fields.

Private Sub cmbComp_AfterUpdate()
Me.cboOff.RowSource = "SELECT ID, Address1, Address2, Address3, Address4, Address5        FROM" & _
 " tblOffice WHERE CompID = " & Me.cmbComp & _
" ORDER BY Address1"
 Me.cboAdjOff = Me.cboAdjOff.ItemData(0)
Me.txtAdd2 = Me.cboOff.Column(2)
Me.txtAdd3 = Me.cboOff.Column(3)
Me.txtAdd4 = Me.cboOff.Column(4)
Me.txtAdd5 = Me.cboOff.Column(5)
End Sub

Not sure what tod do??

A: 

If I understand you correctly, you are looking for the "Requery" statement. This will "refresh" the data in your combobox or form. you can put a

 Me.Requery 

In the relevant Event handler. Probably "AfterUpdate" if I remember correctly.

Loopo
No sorry, its not Me.Requery, as far as i understand it that reloads the entire records.What I would like to find out is; when i move between the records the controling cascading combo box, and the relevant fields that get updated by it are empty.I do not know how to populate these fields when opening a record on a form.Does that make sense?? Thanks for the reply anyhow
glinch
Hi, I got this working using form_current() and setting the values there. Thanks for your help though Loopo.
glinch
Use Me.NameOfCombo.Requery to requery the combo alone.
Remou
A: 

try

row source in the combo box =

"SELECT DISTINCT table.field FROM table;"

finds all unique values in table, alphebetizes them, then makes them into a long drop down menu.

I'm not clear on how this addresses any part of the actual question.
David-W-Fenton