Hi,

Just a form where I want to put a default value for a combobox:

private sub form_load()

me.combobox1.defaultvalue = 3

end sub

The property defaultvalue is giving an error, 'method or data member not found'.

what do you think?

Recommended Answers

All 5 Replies

me.combobox1.text = 3

Hi jX_man,

Not gonna work, I want to put a default value, not an actual value, cos otherwise the record will be added to the database, which I don't want to.
I wrote some VB and in the default value box, called this function. seems to work.

Show us the code. I'm not sure what you need. I understood the same as Jx_Man, unless you are referring to the data on line 3, which will then be something like -

Me.Combobox1.ListIndex = 3
'Will show the value from the 4th entry, starts at 0...

This is what I did, I created this function in a module, and in the defaultvalue prop in Access, I called this function ( = default_jaar() )

Public Function default_jaar() As Integer

If Month(Date) > 4 Then
default_jaar = DLookup("cohort_id", "TBL_cohorten", "startjaar =" & Year(Date))
Else

default_jaar = DLookup("cohort_id", "TBL_cohorten", "startjaar =" & Year(Date) - 1)

End If

End Function

The difference in your approach is that when I follow your code, I actually put a value in the combobox. If I want to cancel the add new record, I already have created a new record (I work with pop-up forms). So when I folow your code, a new id is given to the record, this is something I don't want, hence this solution.

Nice. Happy coding.:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.