简体   繁体   中英

How to programmatically select a value in combo-box?

Good Day all. I have a quick question. I have an openargs value that I'm am trying to use to show up in my combobox (cmbMemberName) on return from another form. The combobox populate the underlining subform. I just can't seem to get the right method. I can't use recordsource cause that would filter out the rest of the records. Rem: I just want the focus on the updated record and loaded into the combobox upon return. Here's the last method I tried.

If Nz(Me.OpenArgs) <> 0 Then

    Me.cmbMemberName.SetFocus
    DoCmd.FindRecord Me.OpenArgs

    MsgBox (Me.OpenArgs)
    Me!cmbMemberName.Dropdown

Else
   ....

The error occurs on the DoCmd. Any suggestions. Thanks. I could load the entire sequence, but don't think that would be necessary.

First you have to set the value of the combo box. Assuming your openargs matches the bound column of the combo box that should simply be

Me.cmbMemberName = Me.OpenArgs

After that you need to get you subform to populate based on the combo box value. Assuming you have set the subform to properly read the value you just need to requery it

Me.MySubForm.requery

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM