set value in combo box

Mr.K

Registered User.
Local time
Today, 03:33
Joined
Jan 18, 2006
Messages
104
I have a form open with an Individual ID (autonumber). A button opens another form (frmNewPayment) in which i would like to add new payment. The frmNewPayment has a combo box with 2 columns (IndividualID, LastName). IndividualID column is bound and hidden. I want to set value in the combo box to the Last Name matching the ID from the main form using vba - how can I do that?

I tried the following:
Code:
Me.IndividualID = Forms![frmIndividuals]!IndividualID
or
Me.IndividualID.value = Forms![frmIndividuals]!IndividualID

..but that gives me an error: "you can't assign a value to this object."


So I guess in short: How can I set value (preselect a row) using VBA for a combo box?
 
me.individualid = forms!formindividuals.individualid

I think that should work for you.
 
I am not sure if that will work for a combo box or not.
 
Robgould said:
I am not sure if that will work for a combo box or not.

This doesn't work for (my) combo box and I think for combo boxes in general?
 
Last edited:
Ok, I still can't figure why this doesn't set the value for my combobox :(
Code:
Private Sub NewClass_Click()

    DoCmd.OpenForm "frmClassRegistration", acNormal
    DoCmd.GoToRecord , , acNewRec
    Me.IndividualID.Value = Forms![frmIndividuals]!IndividualID
    
End Sub

This only opens the form and goes to the new record. I want it to "preselect"(set value) for my combobox. The code sets value for combo if I try to open an existing record instead of going to a new one, but that's not what I need. Am I supposed to enter something to go one step further into "entering a record"? Or is there soemthing like add-record instead of going to new and that's what I should be using??
 
Mr.K said:
Ok, I still can't figure why this doesn't set the value for my combobox :(
Code:
Private Sub NewClass_Click()

    DoCmd.OpenForm "frmClassRegistration", acNormal
    DoCmd.GoToRecord , , acNewRec
    Me.IndividualID.Value = Forms![frmIndividuals]!IndividualID
    
End Sub

Found the problem...
DoCmd.OpenForm "frmClassRegistration", acNormal should be acAdd
 

Users who are viewing this thread

Back
Top Bottom