Form to be clear before 2nd Search

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form that has 1 combo box. When the form is first pull up it comes
up with all field blank. This is what I want. When I do a search on the
combo box and pull in the info - comes in fine. But here is the problem -
when I do another search from the combo box the information for that record
comes up in the correct text boxes but where the fields in the table are
blank it leaves all the old data from the first search - I don't want this.

How can this be fixed?

Also, is there a way to refresh the form to be all blank before the next
search?
 
If this is an unbound form, which is what it sounds like, then you will have
to explicity empty all the controls on your form.
 
How will I be doing this. You don't explain how to "empty all the controls".
How is this done?
 
Dim ctl As Control
Dim frm As Form
Set frm = Forms!MyFormName
With frm
For Each ctl In frm
If ctl.ControlType = acTextBoxThen
ctl.Value = ""
End If
Next
End With

If you have control types other than Text Boxes that have data, then you
need to include that control type in your logic and put in whatever value you
want it to be.
You can find the possible control types in the VB Editor by selecting the
object browser, selecting Access ans the Library, and acTextbox as the search
criteria. Then you will have a list of all the control type constants.
 
If my original assumption that this is an unbound form is correct, then you
would put it right after the code that updates the table.
 
Table/Form should NOT be updating anything. This form is used to View the
infomation only. I will be creating another form for
editing/adding/deleting.

This form is used for users who will be on the phone with the client and
finding fast information about what products the company has and who to call
for more information.

Should I put the code in "Private Sub CTAName_Combo_AfterUpdate()" as there
is nothing showing here?
 
That sound like a good idea.

melwester said:
Table/Form should NOT be updating anything. This form is used to View the
infomation only. I will be creating another form for
editing/adding/deleting.

This form is used for users who will be on the phone with the client and
finding fast information about what products the company has and who to call
for more information.

Should I put the code in "Private Sub CTAName_Combo_AfterUpdate()" as there
is nothing showing here?
 
Below is the code that I've inserted but it stops at "Set
frm=Forms!CTAMain-View

There is a dash not an underscore between Main & View. But when I placed it
in the code it put in spaces. I've tried [ ] and " " and ( ) but nothing
seems to work.

How do you get around this?

Private Sub CTAName_Combo_AfterUpdate()

Dim ctl As Control
Dim frm As Form
Set frm = Forms!CTAMain - View (This is where it's stopping)
With frm
For Each ctl In frm
If ctl.ControlType = acTextBox Then
ctl.Value = ""
End If
Next
End With

End Sub
 
Don't use a dash in any name. The "dash" is the Math symbol for minus.
This is confusing the compiler. change it to something else.

melwester said:
Below is the code that I've inserted but it stops at "Set
frm=Forms!CTAMain-View

There is a dash not an underscore between Main & View. But when I placed it
in the code it put in spaces. I've tried [ ] and " " and ( ) but nothing
seems to work.

How do you get around this?

Private Sub CTAName_Combo_AfterUpdate()

Dim ctl As Control
Dim frm As Form
Set frm = Forms!CTAMain - View (This is where it's stopping)
With frm
For Each ctl In frm
If ctl.ControlType = acTextBox Then
ctl.Value = ""
End If
Next
End With

End Sub


Klatuu said:
That sound like a good idea.
 
Back
Top