Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clear combo box when subform goes to new record...

Status
Not open for further replies.

trayb

Programmer
Sep 30, 2002
25
0
0
US
I have a main form that contains an UNBOUND combo box strictly for navigating thru subform records. The subform has an "Add New" button which runs a DoCmd.GoToRecord,,acNew event. This works exactly like it should.

The problem is that the mainform combo box stays on the previously selected item. Is there a way to clear it when adding a new subform record? In the OnClick event for the "Add New" button, I tried to use:

Me.Parent!cboSelMB.Text = Null 'doesn't like this
Me.Parent!cboSelMB.Value = -1 'clears but wont save

And I've even tried setting the focus to the main form and then directing the mainform to a new record, like this:
(pseudocode)
Forms!mainform!subform.SetFocus
DoCmd.GoToRecord , , acNewRec

Setting the value to -1 clears the combo box, but when I try to save the subform record, access gives me a "duplicate values" error. Since the combo box is unbound, why would it do this? Anybody got any ideas?
 
In the OnCurrent event of the sub-form, try this:

If Me.NewRecord then
Forms!MainFormName!cboSelMB=null
End If _________
Rott Paws

...It's not a bug. It's an undocumented feature!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top