Carl
Carl

Reputation: 5779

Controlling form with Combobox

I have a form with a combo box in the form header that populates the values in the form. I can select different values in the combo box that refer to observations in my table, and the form will filter so that I have all the data from the table for the observation I select in the combo box in the form.

It works fine, however when I open the form, the form is populated with the first row in the table, even though the combobox is blank. How do I set up the form so that when the combobox in the header is blank then the form is blank, and the form only populates when I populate the combobox?

Thanks

Upvotes: 1

Views: 101

Answers (2)

Y2Que
Y2Que

Reputation: 113

You could leave the subform Record Source blank and in the combo box AfterUpdate() event, change the subform Record Source and Requery the subform.

This can be a bit sloppy since form requeries are notorious for their unreliability. What I've done in the past is make the subform a PopUp and in AfterUpdate() of the combo box or on a button click, modify the Record Source and open the desired subform.

Upvotes: 1

Newd
Newd

Reputation: 2185

As I had mentioned in my comment I think what you are trying to do could be fairly annoying to implement. However if you just add something like this:

Private Sub Form_Load()
    Me.Combobox1.Value = Nz(Me.ObservationName,"")
End Sub

It would just make the Comboboxreflect the proper name of the observation that you are viewing. ObservationName is just what I assume is the field name that you use in the Combobox, and Combobox1 would be replaced with the name of your Combobox.

Upvotes: 0

Related Questions