|
-
Nov 10th, 2005, 12:20 PM
#1
Thread Starter
Member
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
-
Nov 10th, 2005, 12:38 PM
#2
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?
-
Nov 10th, 2005, 12:55 PM
#3
Thread Starter
Member
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!
-
Nov 10th, 2005, 01:01 PM
#4
Re: Selecting the default record to be displayed in a combo box
 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.
-
Nov 10th, 2005, 02:48 PM
#5
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
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|