Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

modifying the ListRowSource property in VB

Status
Not open for further replies.

dfwelch

Programmer
Dec 5, 2003
51
US
I want to change the Row Source of a pull-down list based on the value selected in another field on the form. There will be only two possibilities. I can create tables (table1 and table2) containing the values I want in both cases.

I am writing a VB procedure to run at the OnExit event for the later field. Is this the beginning of the correct syntax to make that change, and what is the rest?

If Forms!Form1!Frame10 = 1 Then
Forms!Form1!REFNUM1.ListRowSource =
Else
Forms!Form1!REFNUM1.ListRowSource =
End If
 
I now have it as:
If Forms!Form1!Frame10 = 1 Then
Me.REFNUM1.RowSource = SCA
Else
Me.REFNUM1.RowSource = SOC
End If

where SCA and SOC are the names of the two tables containing the sources. It does not work, but also does not give an error as written.
 
Instead of OnExit I think you need to use AfterUpdate.

Also because tables are often not sorted or I only want to select certain fields for my combo control (I think thats what you mean by pulldown), I use a sorted query e.g.

If Frame10 = 1 Then
REFNUM1.RowSource = "SELECT Field1, Field2 FROM SCA ORDER BY Field1"
Else
REFNUM1.RowSource = "SELECT Field1, Field2 FROM SCO ORDER BY Field1"
End if

Make sure that the Row Source Type is set correctly though.

When you go the the combo control, the correct table should now be loaded.

You should not usually need to use the Me or the Forms collections to refer to controls in the same form (though sometimes the Me is required to avoid confusion). The Forms etc. is normally used to refer to a control an another open form or a subform.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top