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
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?
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!
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. :)
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:
Private Sub Form_Load()
Dim MyRS As ADODB.Recordset
Dim MaxDate As String
Set MyRS = New ADODB.Recordset
With MyRS
.CursorLocation = adUseClient
.Open "SELECT MAX(MYDATE) FROM DATE_SAMPLE", _
CurrentProject.Connection, _
adOpenKeyset, _
adLockOptimistic
Me.Combo0.Value = .GetString(adClipString, 1)
.Close
End With
Set MyRS = Nothing
End Sub