how to clear a form then requery

G

Guest

Hello,

I have a form which (is bound to the employee table) displays an employee
record. When the form opens, all fields, except the EmpID are not visible.
The form opens and the user is prompted for the EmpID. When entered, a
filter is applied and all fields are set to visible. Two command buttons are
on the form. 1st button is Clear form, the 2nd is to terminate the employee,
which will update a few fields on the record. When I click Clear Form, I
would like to clear the current record. By that, I mean I want to clear the
EmpID field, requery so that no record is found with the result being all
fields being empty. Is this a good way to accomplish this, and if so, can
someone advise me on how to do it?


TIA,
Rich
 
K

Ken Snell \(MVP\)

One way you can do this is to set the form's RecordSource property to an
empty string, then set it back to its original value:

Private Sub ClearButton_Click()
Dim strRS As String
strRS = Me.RecordSource
Me.RecordSource = ""
Me.RecordSource = strRS
End Sub


Or you can clear the EmpID control and requery the form (assuming that the
RecordSource uses that EmpID control as a WHERE criterion value source):

Private Sub ClearButton_Click()
Me.EmpID.Value = Null
Me.Requery
End Sub


Or you could run the form's Load event procedure, assuming that it is where
you set controls to invisible, etc.:

Private Sub ClearButton_Click()
Call Form_Load
End Sub


And there probably are many other ways to do what you seek, but it would be
good to tell us if you run any code in the form's load event procedure, what
the form's RecordSource is, what the initial filter for the form is, etc.
 

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