Results 1 to 4 of 4
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is online now Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    2,097

    Can't get combo on form set to 1st row on form open

    The code segment below initializes the three rows of a 2 column combo in the OnOpen Event of a form. The format of the 2 columns is 0";1". I want the combo box to display the default value, the CurYr, when the form opens.



    "Me.cboYears.DefaultValue = CurYr" isn't getting the job done.

    Once I go through a dropdown action everything works properly, it's just when the form opens that the combo appears blank.

    Code:
    Me.cboYears.RowSource = lngCurYrSun & "," & CurYr & ";" & _
                                        lngCurYrSunMinus1 & "," & CurYr - 1 & ";" & _
                                        lngCurYrSunMinus2 & "," & CurYr - 2
    Me.cboYears.DefaultValue = CurYr

  2. #2
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Is CurYr set as the Bound Column of the Combobox, or is it lngCurYrSun?

    For anything related to data, it is usually best to run it in the Form_Load event, rather than in the Form_Open event; data is frequently not available as early as the open event.

    Where/how is CurYr defined?

    Also, I assume that the Row Source Type has been set, somewhere, to Value List; is this correct?

    All of this aside, to open with the first row selected, on New Records (which is what setting the DefaultValue would accomplish) I'd go with this:

    Code:
    Private Sub Form_Current()
     If Me.NewRecord Then
      cboYears.SetFocus
      cboYears.ListIndex = 0
     End If
    End Sub



    Linq ;0)>

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is online now Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    2,097
    BINGO!!

    "Is CurYr set as the Bound Column of the Combobox" The recent upgrading of a single column combo to that of two columns failed to include the designation of column "2" as being the bound column. All I had to do was update the property sheet accordingly and all is now functioning properly.

    Thanks,
    Bill

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Glad we could help!

    Linq ;0)>

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

Similar Threads

  1. Replies: 22
    Last Post: 05-10-2014, 04:43 PM
  2. Using a combo box to open a form in edit
    By gopher in forum Forms
    Replies: 6
    Last Post: 01-18-2014, 11:26 AM
  3. Open form from combo box
    By aceoftrades in forum Access
    Replies: 31
    Last Post: 03-05-2012, 06:02 PM
  4. A Combo box that open another form
    By mar_t in forum Access
    Replies: 14
    Last Post: 01-09-2011, 10:53 PM
  5. Using combo box to open another form
    By ladyairj23 in forum Forms
    Replies: 0
    Last Post: 06-02-2006, 07:03 AM

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