Set combo box default value

  • Thread starter Thread starter Sajit
  • Start date Start date
S

Sajit

I am trying to set the default value of a combo box to the last value with
which the form was closed with.

I was expecting this setting in the 'on form close' to work much the same
way it would if I were to enter the default value in the properties manually.

Private Sub Form_Close()
Forms![list of standards]![Text25].DefaultValue = """" & Forms![list of
standards]!Text25 & """"
Debug.Print Me.Text25.DefaultValue

End Sub

But it does not.

Why does the setting that I do, don't stick in there?

Sajit
Abu Dhabi
 
Sajit

I'm wondering if the "Close" event of the form is really where you want this
to happen. There's a chance that this gets triggered too late...

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
That is because changes to the form are not being saved. To do this, you
will need to close the form using:

Docmd.Close acForm, "MyFormName", acSaveYes

However, this may not be a good idea. What is the value is no longer
available when you open the form the next time?

And, it will not work if a user closes the form using the red x or closes
the application while the form is open.
 
Jeff, Dave,

With the DoCmd I should see the last value set in the default value
properties, provided I close it through a close button that I would have to
create. Perhaps I have to also remove the red x button from the user.

I have done the 'on close' event for forms in VB6 and it does work by the
red x or the close button that I had put in. Is there a work around for it in
VBA for the event getting triggered for the red x 'close'.

Sajit

Jeff Boyce said:
Sajit

I'm wondering if the "Close" event of the form is really where you want this
to happen. There's a chance that this gets triggered too late...

Regards

Jeff Boyce
Microsoft Office/Access MVP

Sajit said:
I am trying to set the default value of a combo box to the last value with
which the form was closed with.

I was expecting this setting in the 'on form close' to work much the same
way it would if I were to enter the default value in the properties
manually.

Private Sub Form_Close()
Forms![list of standards]![Text25].DefaultValue = """" & Forms![list of
standards]!Text25 & """"
Debug.Print Me.Text25.DefaultValue

End Sub

But it does not.

Why does the setting that I do, don't stick in there?

Sajit
Abu Dhabi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top