Help in a form

casper2391

casper2391
Local time
Today, 05:49
Joined
May 26, 2009
Messages
3
Hi all, I hoping someone can help me. I have a button on a form that clears all my fields but I can not get the form to reset once the fileds are cleared without closing and reopening the form. Can someone give me an idea how I can make this work on the button click? Thanks!!!
 
You need to give us a little more info on exactly what you're trying to do here.

What exactly do you mean by "clears all my fields?" Is this a bound or an unbound form?

What do you mean by getting "the form to reset" once the fields are cleared?

Is this form being used for data entry, or as a search form, or what?

Inquiring minds need to know!

And it would probably help to see what code you're currently using on the button.
 
You need to give us a little more info on exactly what you're trying to do here.

What exactly do you mean by "clears all my fields?" Is this a bound or an unbound form?

What do you mean by getting "the form to reset" once the fields are cleared?

Is this form being used for data entry, or as a search form, or what?

Inquiring minds need to know!

And it would probably help to see what code you're currently using on the button.

[It's and unbound form and the code I have working now clears all the unbound text boxes. I have text boxes that are grayed out and I would like them to rest that way after the form is cleared. This form is used for searching.

Code:
Private Sub Clear_Fields_Click()
Dim I As Integer

' Cycle through the form's controls, testing for text,
' and clear each field.
For I = 0 To Me.Count - 1
If TypeOf Me(I) Is TextBox Then
Me(I) = ""
ElseIf TypeOf Me(I) Is ComboBox Then
Me(I) = ""
End If
Next


End Sub

Thannks for your help]
 
The easiest way os to write a simple sub routine that resets all the required fields to the default settings. Ok if you have alot of fields it can be a bit labourious, but remember this is a once only event. Something like

Sub ResetControls()

Me.TxtField1 = ""
Me.TxtField2 = ""
Me.TxtField1.Enabled = False
Me.TxtField2.Enabled = False

Me.Cbo1 = ""
Me.Cbo2 = ""

etc

End sub

Then after you perform a save you issue the command

Call ResetControls


David
 
Thanks David that did what I wanted it to do!!! Thanks Bunches!!!
 
I have a related problem.

I reset all the fields on a search form in a similar way to Caspar in his original post - Do I = 0 to Count etc. This works for all (textbox, combobox, listbox, toggle buttton) except optionbutton which VB won't let me, saying I can't set a value to this field.

I've tried setting the optionbuttons to 0, defaultvalue & false.

I have to list each optionbutton individually & set them to 0.

As this is a form which changes frequently I'd prefer to Do I = 0 to Count.

Any suggestions please - see code below

Private Sub ClrFilter_Click()

'Clear filter entries from screen

Dim I As Integer
Dim Index As Integer

For I = 0 To Forms![Frm Contacts Search].Count - 1
If TypeOf Forms![Frm Contacts Search](I) Is TextBox Then
Forms![Frm Contacts Search](I) = ""
ElseIf TypeOf Forms![Frm Contacts Search](I) Is ComboBox Then
Forms![Frm Contacts Search](I) = ""
ElseIf TypeOf Forms![Frm Contacts Search](I) Is ListBox Then
For Index = 0 To Forms![Frm Contacts Search](I).ListCount - 1
Forms![Frm Contacts Search](I).Selected(Index) = False
Next Index
'next bit doesn't work
ElseIf TypeOf Forms![Frm Contacts Search](I) Is OptionButton Then
Forms![Frm Contacts Search](I) = 0
ElseIf TypeOf Forms![Frm Contacts Search](I) Is ToggleButton Then
Forms![Frm Contacts Search](I).Value = Forms![Frm Contacts Search](I).DefaultValue
End If
Next I

'Option buttons - this works
Me!Broxbourne = 0
Me!Dacorum = 0
'etc - there are lots of these

End Sub
 
Rosemary,

If you are still looking for an answer, look here:
http://allenbrowne.com/ser-56.html

_________________
Regards,
Marvin M :cool:
Windows 7 Professional, MS Access 2007/2010
Windows 8 Professional, MS Access 2013
---------------------------------------------------------------------------------------------
If my post has helped you, please click the scales or click the 'Thumbs up'. Thanks!
---------------------------------------------------------------------------------------------
 

Users who are viewing this thread

Back
Top Bottom