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?

7 Years
Discussion Span
Last Post by AndreRet

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...

Edited by AndreRet: n/a


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))

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.