Combobox defaultvalue changes

  • Thread starter Thread starter Rucus
  • Start date Start date
R

Rucus

I am trying to change the default values of a combobox in the afterupdate
event. When I check the properties teh default value field has been updated
but once I close the form and reopen it the default value has reverted back
to what it was previously set to. Any suggestions are appreciated.
 
Rucus,
this is normal behaviour for default values set in code in the after update
event.
Once you close the form the last-used default value is lost - it is not
actually saved anywhere on the form. However the default value entered on
the property dialog is saved and used each time the form opens.

Jeanette Cunningham
 
Thanks Jeanette for your reply,
Is there a way to bypass this behavior? I have tried to save the form
after updating the value. I am trying to have the form open to the user
preference. Some background for this project is; the user is entering Water
Quality data that can have hundreds of constituents tested, but generally
there are a limited amount of constituents tested based on location, so if
the user can choose what is tested in their location the first time they
enter data then the next time the form opens the will have the constituents
they use already seleceted.
 
Yes, it can be done.
Create a table for user settings. If each user has their own copy of the
front end, you can put this table in the front end. The table records the
default value for the field/s involved. You allow only one row in this
table. When your form opens, it sets the default value using a DLookup to
the relevant field/s in the user settings table.
Me.txtConstituent.DefaultValue = DLookup("[Constituent]", "tblUserSettings")
'numbers

Me.txtConstituent.DefaultValue = """ & DLookup("[Constituent]",
"tblUserSettings") & """ 'text

Me.txtConstituent.DefaultValue = "#" & DLookup("[Constituent]",
"tblUserSettings") & "#" 'date

Jeanette Cunningham
 
Thanks for your help.
--
Rucus


Jeanette Cunningham said:
Yes, it can be done.
Create a table for user settings. If each user has their own copy of the
front end, you can put this table in the front end. The table records the
default value for the field/s involved. You allow only one row in this
table. When your form opens, it sets the default value using a DLookup to
the relevant field/s in the user settings table.
Me.txtConstituent.DefaultValue = DLookup("[Constituent]", "tblUserSettings")
'numbers

Me.txtConstituent.DefaultValue = """ & DLookup("[Constituent]",
"tblUserSettings") & """ 'text

Me.txtConstituent.DefaultValue = "#" & DLookup("[Constituent]",
"tblUserSettings") & "#" 'date

Jeanette Cunningham
 
I forgot to say how to save the default value.
Use the form's after update event to send the default value for the field/s
to the user settings table.

Dim strSQL as String
Dim db as DAO.Database

Set db = dbengine(0)(0)

strSQL = "INSERT INTO tblUserSettings ( Constituent ) " _
& "VALUES ( " & Me.txtConstituent & " )"
Debug.Print strSQL

If DCount("[Constituent]", "tblUserSettings") = 0 Then
db.Execute strSQL, dbFailOnError
End If

Set db = Nothing

----------------------------------------------------
change the second line of the SQL depending on the data type:
For a number field use " & Me.txtConstituent & "
For a text field use """ & Me.txtConstituent & """
For a date field use "#" & Me.txtConstituent & "#"

Jeanette Cunningham
 
Thanks, that worked perfect.
--
Rucus


Jeanette Cunningham said:
I forgot to say how to save the default value.
Use the form's after update event to send the default value for the field/s
to the user settings table.

Dim strSQL as String
Dim db as DAO.Database

Set db = dbengine(0)(0)

strSQL = "INSERT INTO tblUserSettings ( Constituent ) " _
& "VALUES ( " & Me.txtConstituent & " )"
Debug.Print strSQL

If DCount("[Constituent]", "tblUserSettings") = 0 Then
db.Execute strSQL, dbFailOnError
End If

Set db = Nothing

----------------------------------------------------
change the second line of the SQL depending on the data type:
For a number field use " & Me.txtConstituent & "
For a text field use """ & Me.txtConstituent & """
For a date field use "#" & Me.txtConstituent & "#"

Jeanette Cunningham
 
Back
Top