Results 1 to 15 of 15
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    Assigning value to combo not working

    I have a form where under certain conditions I need a combo box pre-selected. I thought my OPEN code would do that trick, but no. What am I missing?
    Code:
    If IsNull(Me.OpenArgs) Then
        Me.cmbGroups.DefaultValue = "[cmbGroups].[itemdata](0)"
    Else
        Me.cmbGroups.Value = Me.OpenArgs
    End If


  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    you cant put quotes around a form object, it wont resolve, so try:

    Me.cmbGroups= cmbGroups.itemdata(0)

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Oops! That statement is older than I am . I've removed the quotes.

    However, the OP has to do with the use of an combo item value passed to the form in OpenArgs where I want to set the combo accordingly when the form opens. I.e., have the OPEN code behave as though the user has already selected the value from dropdown and pressed enter. (I'll probably also need to call the After_Update event code to trigger the corresponding action)

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,933
    I would have thought you would need the load event, before any data was available?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Yes, that was one of my thoughts as well.
    Code:
       If Not IsNull(Me.OpenArgs) Then _
            Me.cmbGroups = Me.OpenArgs
    In the OnLoad didn't seem to have any effect on the initial conditions of the receiving form.

  6. #6
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Code:
    Me.cmbGroups.DefaultValue = "[cmbGroups].[itemdata](0)"
    Try .value instead of .defaultvalue.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  7. #7
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    I'm not trying to set the default value, just effectively pre-select a value when a form opens/loads.

  8. #8
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    In the OnLoad event:

    Code:
       If Not IsNull(Me.OpenArgs) Then
            Me.cmbGroups.SetFocus
            Me.cmbGroups.Text = Me.OpenArgs
       End If
    Problem solved.

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,933
    Quote Originally Posted by GraeagleBill View Post
    I'm not trying to set the default value, just effectively pre-select a value when a form opens/loads.
    Well, that is not what your code was showing?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    I've read this at least twice and am not sure if it's solved or not. Why not just like this?
    Code:
    Private Sub Form_Load()
    If Not Isnull(Me.OpenArgs) Then Me.cmbName = Me.OpenArgs
    End Sub
    EDIT - so I missed the line "problem solved" but at least I know that what I posted works. Not sure why the set focus and text thing should be necessary. I don't see that it matters if you use the load event because you don't need data in the form if the combo value is governed by the open args property. Oh well...
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  11. #11
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    I reverted my code, as I once had it, back to what you suggest and my form opens WITHOUT the OpenArgs appearing as being selected. The intent is to make the form, when opened, appear as though the user has already dropped the combo and selected the item that was passed in OpenArgs.
    Code:
    Private Sub Form_Load()
       If Not IsNull(Me.OpenArgs) Then Me.cmbGroups = Me.OpenArgs
           ' Me.cmbGroups.SetFocus
           ' Me.cmbGroups.Text = Me.OpenArgs
       'End If

  12. #12
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    my form opens WITHOUT the OpenArgs appearing as being selected.
    Don't know what to tell you then except that it works for me.

    Private Sub Command15_Click()
    DoCmd.OpenForm "form2", , , , , , 1236

    Click image for larger version. 

Name:	1236.jpg 
Views:	11 
Size:	4.7 KB 
ID:	45565
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  13. #13
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,933
    Quote Originally Posted by GraeagleBill View Post
    I reverted my code, as I once had it, back to what you suggest and my form opens WITHOUT the OpenArgs appearing as being selected. The intent is to make the form, when opened, appear as though the user has already dropped the combo and selected the item that was passed in OpenArgs.
    Code:
    Private Sub Form_Load()
       If Not IsNull(Me.OpenArgs) Then Me.cmbGroups = Me.OpenArgs
           ' Me.cmbGroups.SetFocus
           ' Me.cmbGroups.Text = Me.OpenArgs
       'End If
    Have you tested that you have a value in OpenArgs?
    Is the parameter correct in the open form?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  14. #14
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Have you tested that you have a value in OpenArgs?
    Is the parameter correct in the open form?
    Yes, those kinds of tests are among the first when intended behavior fails.

  15. #15
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,933
    Quote Originally Posted by GraeagleBill View Post
    Yes, those kinds of tests are among the first when intended behavior fails.
    You say that, but you'd be surprised at the number of people who do not even do that.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Assigning a value to combo box choices?
    By Hopeloma in forum Access
    Replies: 2
    Last Post: 06-30-2017, 05:46 PM
  2. Replies: 10
    Last Post: 10-19-2016, 02:33 PM
  3. Assigning a combo box
    By chr1stoper1 in forum Access
    Replies: 2
    Last Post: 08-25-2015, 01:04 PM
  4. Replies: 3
    Last Post: 08-15-2012, 06:48 AM
  5. Assigning controls not working
    By SemiAuto40 in forum Programming
    Replies: 5
    Last Post: 10-20-2011, 06:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums