Page 1 of 2 12 LastLast
Results 1 to 15 of 26
  1. #1
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Seattle, Washington, USA
    Posts
    179
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Setting an unbound combo box value

    I have a slightly different twist to the question I had posted last week about using SetValue in order to set a combo box on a different form to match the name on the form. The procedure I had described last week (subscriberID.DefaultValue = Forms!Subscribers!SubscriberID) works ONLY if the combo box is bound to SubscriberID.

    This one, I need to set an UNBOUND combo box to match the name that I select in another form.

  2. #2
    New Lounger
    Join Date
    Mar 2002
    Location
    Omaha, Nebraska, USA
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting an unbound combo box value

    I am assuming that you are selecting the name on the second form from a combo box. The code should look like this:

    Private Sub Combo0_Change()
    Form_Form1.Combo0.Value = Form_Form2.Combo0.Value
    End Sub

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Setting an unbound combo box value

    Depending on which form you're setting the value from, here's a more standard syntax.

    <pre>From form1:

    forms!form2!Combo0 = Me!Combo0

    From elsewhere (but not form2):

    forms!form2!Combo0 = forms!form1!Combo0</pre>


    It doesn't hurt to include the Value property, but since it's the default for editable Access controls, it isn't necessary.

    Understand, though, that this assumes that the comboboxes on both forms have the same values in the first column.
    Charlotte

  4. #4
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Seattle, Washington, USA
    Posts
    179
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting an unbound combo box value

    Thanks to you both for your suggestions. I had finally figured out why it wasn't working (I'm still relatively new to VBA).

    I had attempted to open a dialog box whenever the item isn't in the list in the main form. I belatedly realized that if the item wasn't in the list the first time around, then I wouldn't be able to set the dialog box combo box to match the main form (no key).

    If you have an idea of how I could somehow parse the name in the main form's combo box into the dialog box, that'd be great.

    Again, thanks in advance for your help.

  5. #5
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    NYC,USA,Earth
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting an unbound combo box value

    The value of the combobox is passed to the notinlist event as the NewData argument.

  6. #6
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Seattle, Washington, USA
    Posts
    179
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting an unbound combo box value

    Paul, thanks for the tip. Now, I'm not sure how do I write a code that pastes NewData into the unbound combo box on the dialog box?

    I've tried Mid statement (can see the NewData content) but how do I tell it to actually insert it into the combo box?

  7. #7
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    NYC,USA,Earth
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting an unbound combo box value

    This should work:

    Forms!MyFormName!MyComboboxControlName = NewData

  8. #8
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Seattle, Washington, USA
    Posts
    179
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting an unbound combo box value

    We are getting there. When I set the breakpoint in the VB editor, and I see it says: "cboName=Traub, Carolyn" but the dialog box still shows the Name combo box as blank. Am I missing something?

    This is what I did: Forms!fldgSetAppStatus!cboName=NewData and this is the last line in the code. Does the order of code affect this somehow?

  9. #9
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    NYC,USA,Earth
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting an unbound combo box value

    Could you post the entire procedure?

  10. #10
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Seattle, Washington, USA
    Posts
    179
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting an unbound combo box value

    I can't seem to attach it...

    Here's the code:

    Private Sub cboName_NotInList(NewData As String, Response As Integer)
    ' If not listed, then open fldgSetAppStatus

    Dim strTitle As String
    Dim intMsgDialog As Integer
    Dim strMsg1 As String
    Dim strMsg2 As String
    Dim strMsg As String
    Dim strEntry As String
    Dim strFormName As String
    Dim frm As Form
    Dim intReturn As Integer
    Dim strName As String

    strFormName = "frmAcceptance"
    strEntry = "ParticipantID"
    Set frm = Forms(strFormName)

    'Display a message box asking if the user wants to add
    'a new entry
    strTitle = strEntry & " Not in List"
    intMsgDialog = vbOK + vbExclamation + vbDefaultButton1
    strMsg1 = "You need to set "
    strMsg2 = "'s App Status."
    strMsg = strMsg1 + NewData + strMsg2
    intReturn = MsgBox(strMsg, intMsgDialog, strTitle)

    If intReturn = vbCancel Then
    Response = acDataErrContinue
    frm.Undo
    Exit Sub
    ElseIf intReturn = vbOK Then
    'Open form for adding new client
    frm.Undo
    Response = acDataErrContinue
    DoCmd.OpenForm "fldgSetAppStatus"
    Forms!fldgSetAppStatus!cboName = NewData
    End If

    End Sub

  11. #11
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    NYC,USA,Earth
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting an unbound combo box value

    Why are you using a combobox on the second form? I looked at an example I did and I used the OpenArgs argument of the OpenForm method to pass the string in the NewData variable to the second form. Then in the Open event of the second form I set the value of the control to the OpenArgs property of the form (which should be the same as the NewData string).

    DoCmd.OpenForm "fdlgAddRCode", , , , , acDialog, NewData

    Me!txtCode = UCase(Me.OpenArgs)

  12. #12
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Seattle, Washington, USA
    Posts
    179
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting an unbound combo box value

    The reason there is a combo box on the second form is because I was trying to filter my main form combo box to show only participants who were accepted to camp. For reasons too lengthy to list here, I couldn't use conventional filtering so I had to set the combo box to list participants based on their Application Status (Waiting List, Accepted and Not Accepted). If the person is still on Waiting List, then that person wouldn't show up on the combo box. This is where my code fires and opens second form which enables me to look up that person and change the status and then requeries the main form so that the person would show up there.

    1. Does the code you just posted work with combo boxes?
    2. I don't understand your code. Which parts of it that I need to switch with names of my forms/fields?

    Thanks for your time and patience! I'm learning a lot from this.

  13. #13
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    NYC,USA,Earth
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting an unbound combo box value

    Sorry for the unexplanation but it's been one of those days. See below for details:

    'bold text represents objects you will need to rename to your own object names.

    'This will open a form in dialog mode passing the value from form 1 to form 2 using the OpenArgs argument.
    DoCmd.OpenForm "fdlgAddRCode", , , , , acDialog, NewData

    'In the On Open event of form 2 set the control's value to the form's OpenArgs property and set the text in upper case (remove the UCase function if you don't need that part).
    Me!txtCode = UCase(Me.OpenArgs)

    I'm not sure if this will work with a combobox or not I don't have time to test it out just now. Perhaps tomorrow.

  14. #14
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Seattle, Washington, USA
    Posts
    179
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting an unbound combo box value

    I'll test the code, you have done a lot by giving me suggestions, I don't want to impose on you too much. Smile.

    Thanks for the clarification, I tried your code, at the break points, I can see that the name of participant is being passed on but still refuse to show up in the dialog box. I'm gonna look up in my reference book because I recall seeing a similiar situation that worked before...

  15. #15
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    NYC,USA,Earth
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting an unbound combo box value

    Are there any other columns in the combobox on the second form besides name? And the name is showing up in th on open event of the second form? Strange.... <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •