Clearing Parameters in a form using a Cmd Button (1 Viewer)

KW99

Registered User.
Local time
Today, 04:34
Joined
Nov 30, 2008
Messages
36
I have set up a a form to select the parameters for a query.

I have tried to create a button for the user to clear all of the parameters to save them having to do it one by one manually or having to close the form and reopen.

I have used the following Event Procedure:

Private Sub Command31_Click()
Me.tskref1.Value = ""
Me.cname1.Value = ""
Me.admin1.Value = ""
Me.daterecd1.Value = ""
Me.tskdesc1.Value = ""
Me.memtsk1.Value = ""
Me.admin2.Value = ""
Me.complete1.Value = ""
End Sub

It clears the data fine, however when some new data is entered it states that Run Time error 2001 has occurred "you cancelled the previous operation".

I am sure I have just missed off a bit of code somewhere to reset the parameters or something.

Has anyone any ideas?

Thanks in advance

K
 

wazz

Super Moderator
Local time
Today, 19:34
Joined
Jun 29, 2004
Messages
1,711
are those controls bound to the recordsource?
it looks like they're all textboxes. if so maybe this will help:
Code:
    Dim ctlCurrent As Control
 
    For Each ctlCurrent In Me.Controls
        If ctlCurrent.ControlType = acTextBox Then
            ctlCurrent.Value = ""
        End If
    Next ctlCurrent
 

KW99

Registered User.
Local time
Today, 04:34
Joined
Nov 30, 2008
Messages
36
Hi, all of the fields are combo boxes, which get the data from tables.

I cant seem to get what you have suggested to work and I think it is because of this.

On the other hand it might be me misinterpreting what you are suggesting. I am not the worlds foremost expert when it comes to Access and programming!!!

Thanks

K
 

wazz

Super Moderator
Local time
Today, 19:34
Joined
Jun 29, 2004
Messages
1,711
right, my suggestion was for textboxes. if they're all comboboxes then
Me.tskref1 = Null
Me.cname1 = Null
Me.admin1 = Null
etc.

or
Code:
    Dim ctlCurrent As Control
    For Each ctlCurrent In Me.Controls
        If ctlCurrent.ControlType = acComboBox Then
            ctlCurrent = Null   
        End If
    Next ctlCurrent
does either of those fix the problem?

btw, you said, "when some new data is entered...". do you mean, when new data is selected or entered? are people entering (new) data into the comboboxes?
 

KW99

Registered User.
Local time
Today, 04:34
Joined
Nov 30, 2008
Messages
36
When I was talking about entering 'new' data, I meant the user had cleared the selection and was selecting new data from the combo boxes.

The = null method works fine thanks and with no errors.

Thank you very much for your time and help.

K
 

Users who are viewing this thread

Top Bottom