Clearing contents of controls (combo box and sub form)

R

Rob W

Greetings,

I have combo box and a sub form that appears after updates/click of combo
box.

I have a clear button on the form which runs the following code:-

Private Sub cmdClear_Click()

Me.cboModuleName.SetFocus
Me.cboModuleName.Text = ""
Me.frmModuleResultsSubform.Enabled = False
Me.frmModuleResultsSubform.Visible = False

End Sub

It wont let me change the subform because apparently you cant disable a
control while it has focus.
I also had to set the focus to the subform manually (see below) as It only
allowed me to tab through field on the main form, this ONLY happens if i
used the CLEAR button else the focus goes to the subform even if there are
no rows, and allows data entry.

Private Sub cboModuleName_Click()

Me.frmModuleResultsSubform.Enabled = True
Me.frmModuleResultsSubform.Visible = True
Me.frmModuleResultsSubform.SetFocus
Me.frmModuleResultsSubform.Requery


End Sub

Can anyone think of an easer way, to have a clear button that clears combo
box and the sub form?

Thanks
Rob
 
T

Tom Wickerath

Hi Rob,
Can anyone think of an easer way, to have a clear button that clears combo
box and the sub form?

Yes. I never try to change the .Enabled or .Visible properties of the
subform when clearing. One method involves setting the recordsource for the
subform to a query that is guaranteed to return zero records. For instance:

SELECT * FROM MyTable WHERE False;

Try these QBF (Query By Form) samples:

http://www.accessmvp.com/TWickerath/downloads/elements.zip
http://www.accessmvp.com/TWickerath/downloads/Chap08QBF.zip


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 

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

Top