Results 1 to 5 of 5

Thread: Selecting the default record to be displayed in a combo box

  1. #1

    Thread Starter
    Member
    Join Date
    May 2005
    Posts
    56

    Selecting the default record to be displayed in a combo box

    Hello Everyone,

    I have a combo box connected to a table. On the table there are multiple dates. I want the most recent date to be the one that displays in the combo box by default. Is this possible, I was trying to mess around with recordset but no luck. Thanks in advance!

    Hizaed

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Selecting the default record to be displayed in a combo box

    By most recent do you mean the date that is closest to the current date?

    Are you using ADO?

  3. #3

    Thread Starter
    Member
    Join Date
    May 2005
    Posts
    56

    Re: Selecting the default record to be displayed in a combo box

    Correct... the date that is closest to the current date. I do not know what ADO is. Would it matter that I am doing it in Access 2003 ? Thanks again!

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Selecting the default record to be displayed in a combo box

    Quote Originally Posted by Hizaed
    Correct... the date that is closest to the current date. I do not know what ADO is. Would it matter that I am doing it in Access 2003 ? Thanks again!
    Yes, it would matter. Access VBA is different than VB6. In the ClassicVB section, you would get answers to your questions from a VB6 standpoint, which may, or may not, work in Access VBA.

    Here, however, the responses to your question will be in code you can use.

    Moved to Office Development.

  5. #5
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Selecting the default record to be displayed in a combo box

    Hizaed
    Here's some sample code that uses a recordset to select the max date in combo0. I am running the code when the form loads. You will need to change the SQL statement in the Open method of the recordset and change "Me.Combo0" to a valid reference for your combobox.

    VB Code:
    1. Private Sub Form_Load()
    2. Dim MyRS As ADODB.Recordset
    3. Dim MaxDate As String
    4.    
    5.     Set MyRS = New ADODB.Recordset
    6.     With MyRS
    7.         .CursorLocation = adUseClient
    8.         .Open "SELECT MAX(MYDATE) FROM DATE_SAMPLE", _
    9.                 CurrentProject.Connection, _
    10.                 adOpenKeyset, _
    11.                 adLockOptimistic
    12.         Me.Combo0.Value = .GetString(adClipString, 1)
    13.         .Close
    14.     End With
    15.    
    16.     Set MyRS = Nothing
    17. End Sub
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

Posting Permissions

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



Click Here to Expand Forum to Full Width