On click event procedure with a combo box

A

amjjam

Hi,

I have a contacts form which is a subform of a company form. If the
contact’s information is the same as the company information, one can usually
fill in the form field by simply clicking on it. If, for example, the
contact’s fax number is the same as the company’s fax number the code for the
on click event procedure reads:

Private Sub ContactFaxNumber_Click()
Me!ContactFaxNumber = Me.Parent!CoFaxNumber
End Sub

I have put the following similar code in the State field:

Private Sub ContactStateNameID_Click()
Me!ContactStateNameID = Me.Parent!CompanyStateNameID
End Sub

The form has a combo box of state name abbreviations. The on click doesn’t
work for the combo box. In addition, I’d like for it to have a default value
of MO. Entering [ContactStateNameID].ItemData(24) doesn’t work, as the field
remains blank; the drop down box does, however let one choose MO. The row
source type is set to Table/Query. The row source is set to SELECT [Company
State Names].CompanyStateNameID, [Company State Names].StateNameAbbreviation
FROM [Company State Names]; with a column count of 2 and 1 bound column.
Could anyone tell me how to fix this? Do I need to remove the combo box
function from the state field to have the on click event work OR choose to
keep the combo box, fix the default value, and simply get rid of the on click
event? Can both work simultaneously with a default value of MO? Thanks for
any help, amjjam
 
K

Klatuu

For a Combo Box, you use the After Update event, not the Click event. Also,
you may have to specify the column to use. For example if the value you want
to put in the other control is in the second column, you would want to use:

Me!ContactStateNameID = Me.Parent!CompanyStateNameID.Column(1)


To default to MO, use the Default Value property of the combo box to set the
value.
 
A

amjjam

Thanks Dave. This works perfectly. ~ amjjam

Klatuu said:
For a Combo Box, you use the After Update event, not the Click event. Also,
you may have to specify the column to use. For example if the value you want
to put in the other control is in the second column, you would want to use:

Me!ContactStateNameID = Me.Parent!CompanyStateNameID.Column(1)


To default to MO, use the Default Value property of the combo box to set the
value.

--
Dave Hargis, Microsoft Access MVP


amjjam said:
Hi,

I have a contacts form which is a subform of a company form. If the
contact’s information is the same as the company information, one can usually
fill in the form field by simply clicking on it. If, for example, the
contact’s fax number is the same as the company’s fax number the code for the
on click event procedure reads:

Private Sub ContactFaxNumber_Click()
Me!ContactFaxNumber = Me.Parent!CoFaxNumber
End Sub

I have put the following similar code in the State field:

Private Sub ContactStateNameID_Click()
Me!ContactStateNameID = Me.Parent!CompanyStateNameID
End Sub

The form has a combo box of state name abbreviations. The on click doesn’t
work for the combo box. In addition, I’d like for it to have a default value
of MO. Entering [ContactStateNameID].ItemData(24) doesn’t work, as the field
remains blank; the drop down box does, however let one choose MO. The row
source type is set to Table/Query. The row source is set to SELECT [Company
State Names].CompanyStateNameID, [Company State Names].StateNameAbbreviation
FROM [Company State Names]; with a column count of 2 and 1 bound column.
Could anyone tell me how to fix this? Do I need to remove the combo box
function from the state field to have the on click event work OR choose to
keep the combo box, fix the default value, and simply get rid of the on click
event? Can both work simultaneously with a default value of MO? Thanks for
any help, amjjam
 

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