Default value in combobox, but record will not save (1 Viewer)

CuriousGeo

Registered User.
Local time
Today, 05:51
Joined
Oct 15, 2012
Messages
59
Hello, I have a strange situation which has me stumped. I have a main form with a subform and a combobox. Originally, when you selected an item in the combobox on the main form, the record would save (i.e. an Autonumber was generated). Then you could go about your data entry in the subform.

But now that I made the combox have a default value, when you go to the subform and enter data, I notice that the master record (main form) never generates the Autonumber. However, if you physically go to the combobox and reselect the default value, the autonumber gets generated.

What do I need to do to get that record saved initially without having to do something with the combobox, since it already has the default value displayed?
 

Ranman256

Well-known member
Local time
Today, 05:51
Joined
Apr 9, 2015
Messages
4,337
you CANNOT enter subform data until the Master record has been saved.
Make sure when you enter the subform, make an event to save the Master.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:51
Joined
Oct 29, 2018
Messages
21,357
Hi. You probably already know this already, but a DefaultValue doesn't get assigned until a new record is generated. Just because you can see it on the screen doesn't mean it exists yet.
 

CuriousGeo

Registered User.
Local time
Today, 05:51
Joined
Oct 15, 2012
Messages
59
OK, thanks for the comments. I figured out what to do. Leaving my solution in case anyone in the future happens to find this post in a search.

I had to dirty the record, I did that by a Lost Focus event of my combobox (after setting that combo to have the focus)

Private Sub cboName_LostFocus()

Me!cboName.SetFocus
Me.Dirty = True

End Sub

It worked and the record was saved/autonumber was generated.

Thanks
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:51
Joined
Oct 29, 2018
Messages
21,357
Hi. Congratulations! Glad to hear you got it sorted out. Good luck with your project.
 

Users who are viewing this thread

Top Bottom