How to get information in a form using a combo-box?

  • Thread starter Thread starter Amit
  • Start date Start date
A

Amit

Hi,

I have a form to enter Organization Representative
information. There is a combo-box to select the
Organization for the Representative. On selecting the
Organization name from the combo-box, I'd like the Address
fields for the Representative to be filled in with the
address of the Organization. This information is stored in
the tblOrganization.

I'm not sure how to do this. Any pointers will be
appreciated.

On updating the combo-box, will I have to run a query to
get the Address fields from the tblOrganization and assign
them to the fields in the form? Is there another way to do
this without running a query?

Thanks!

-Amit
 
I do this with DLookUps (check the HELP files for details)
in the AfterUpdate event:

Private Sub cboOrg_AfterUpdate()

' if there is not an org selected, stop the code
If IsNull([cboOrg]) Or [cboOrg]="" Then
Exit Sub
End If

' otherwise, lookup the address fields for the
' selected org
Dim strAddress As String
Dim strCity As String

strAddress = DLookUp("[Address]", "tblOrganizations", _
"[OrgID]='" & [cboOrg] & "'")
strCity = DLookUp("[City]", "tblOrganizations", _
"[OrgID]='" & [cboOrg] & "'")

' populate the values into the appropriate controls
[txtOrgAddress] = strAddress
[txtOrgCity] = strCity

End Sub

Hope this helps!

Howard Brody
 
Thanks a lot! Duh.

Just wondering if I have to do two assignments, or can I
get away with:
[txtOrgAddress] = Dlookup (blah)??

-Amit
-----Original Message-----
I do this with DLookUps (check the HELP files for details)
in the AfterUpdate event:

Private Sub cboOrg_AfterUpdate()

' if there is not an org selected, stop the code
If IsNull([cboOrg]) Or [cboOrg]="" Then
Exit Sub
End If

' otherwise, lookup the address fields for the
' selected org
Dim strAddress As String
Dim strCity As String

strAddress = DLookUp("[Address]", "tblOrganizations", _
"[OrgID]='" & [cboOrg] & "'")
strCity = DLookUp("[City]", "tblOrganizations", _
"[OrgID]='" & [cboOrg] & "'")

' populate the values into the appropriate controls
[txtOrgAddress] = strAddress
[txtOrgCity] = strCity

End Sub

Hope this helps!

Howard Brody
-----Original Message-----
Hi,

I have a form to enter Organization Representative
information. There is a combo-box to select the
Organization for the Representative. On selecting the
Organization name from the combo-box, I'd like the Address
fields for the Representative to be filled in with the
address of the Organization. This information is stored in
the tblOrganization.

I'm not sure how to do this. Any pointers will be
appreciated.

On updating the combo-box, will I have to run a query to
get the Address fields from the tblOrganization and assign
them to the fields in the form? Is there another way to do
this without running a query?

Thanks!

-Amit
.
.
 
Hi Howard,

Thanks for the tip. That worked!!
:)

-Amit
-----Original Message-----
I do this with DLookUps (check the HELP files for details)
in the AfterUpdate event:

Private Sub cboOrg_AfterUpdate()

' if there is not an org selected, stop the code
If IsNull([cboOrg]) Or [cboOrg]="" Then
Exit Sub
End If

' otherwise, lookup the address fields for the
' selected org
Dim strAddress As String
Dim strCity As String

strAddress = DLookUp("[Address]", "tblOrganizations", _
"[OrgID]='" & [cboOrg] & "'")
strCity = DLookUp("[City]", "tblOrganizations", _
"[OrgID]='" & [cboOrg] & "'")

' populate the values into the appropriate controls
[txtOrgAddress] = strAddress
[txtOrgCity] = strCity

End Sub

Hope this helps!

Howard Brody
-----Original Message-----
Hi,

I have a form to enter Organization Representative
information. There is a combo-box to select the
Organization for the Representative. On selecting the
Organization name from the combo-box, I'd like the Address
fields for the Representative to be filled in with the
address of the Organization. This information is stored in
the tblOrganization.

I'm not sure how to do this. Any pointers will be
appreciated.

On updating the combo-box, will I have to run a query to
get the Address fields from the tblOrganization and assign
them to the fields in the form? Is there another way to do
this without running a query?

Thanks!

-Amit
.
.
 
Back
Top