Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


default value in combo box based on max value

default value in combo box based on max value

default value in combo box based on max value

I have this working as intended using vba.


was wondering if is possible to do within the combo box to have the default value be the highest(max value). The combobox row source is:

SELECT DISTINCT mid([tblSurveyExtract_Course].[EventCode],2,2) FROM [tblSurveyExtract_Course] ORDER BY 1

and using the above when the combo box is clicked:

In this case, I would like 16 to be the default so that there is no need to select the value from the drop down, unless need to view a different number.

RE: default value in combo box based on max value

I've never tried to use a max for a default value. I think this would work:
Max(mid([tblSurveyExtract_Course].[EventCode],2,2) FROM [tblSurveyExtract_Course])
Please let me know.

RE: default value in combo box based on max value

After populating your combo box, you may want to do something like:

ComboBox1.ListIndex = ComboBox1.ListCount - 1

Have fun.

---- Andy

There is a great need for a sarcasm font.

RE: default value in combo box based on max value

Laurie, that is what I have in my vba. Probably should have included in my post, but since was working properly, didn't want to confuse the issue.

I thought about using dmax but couldn't figure out the syntax to pull the substring out for that purpose.


Private Sub Form_Load()
'Set the default year to the highest year
'based on the eventcode
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim stsql As String
    stsql = "SELECT max(mid([tblSurveyExtract_Course].[EventCode],2,2)) AS EvalYear FROM [tblSurveyExtract_Course]"
    Set db = CurrentDb
    Set rs = db.OpenRecordset(stsql, dbOpenDynaset)
    Me.cboYear = rs!EvalYear
    Set rs = Nothing
    Set db = Nothing
End Sub 

Andy, I tried substituting your code in the Form_Load event and says You've used the ListIndex property incorrectly.


Private Sub Form_Load()
    Me.cboYear.ListIndex = Me.cboYear.ListCount - 1
End Sub 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close