clearing the form: hard way to say UNDO

judgehopkins

Registered User.
Local time
Today, 14:03
Joined
May 29, 2003
Messages
13
This code is for this situation: a user goes back to a saved record
(thus, undo in the before update event is no longer possible)
and changes a programmatically-required control
(i.e., the field is not made required in the table).

The code works EXCEPT for when it gets to MyControl.CheckBox = -1.

I just don't know the syntax. What is it?

Thanks!

Code:
Private Function ClearForm()
Dim MyForm As Form, MyControl As Control
 For Each MyForm In Forms
   For Each MyControl In MyForm.Controls
    If TypeOf MyControl Is TextBox Then
      MyControl.Enabled = True
      MyControl.Visible = True
      MyControl.SetFocus
      MyControl.Text = ""
     ElseIf TypeOf MyControl Is ComboBox Then
      MyControl.Enabled = True
      MyControl.Visible = True
      MyControl.SetFocus
      MyControl.ListIndex = -1
    ElseIf TypeOf MyControl Is ListBox Then
      MyControl.Enabled = True
      MyControl.Visible = True
      MyControl.SetFocus
      MyControl.ListIndex = -1
     ElseIf TypeOf MyControl Is CheckBox Then
      MyControl.Enabled = True
      MyControl.Visible = True
      MyControl.SetFocus
 	MyControl.CheckBox = -1
     End If
  Next MyControl
 Next MyForm
End Function
 
Instead of

MyControl.CheckBox = -1

try

Mycontrol.value=-1


You don't need to setfocus to the control you're clearing because you're referencing the control. I presume that youmay have hidden it.
 
I had to set focus when going through the loop according to the debugger. What you say makes sense, but it doesn't work that way!

Anyway, here is the code after I got through with it. It clears everything but the items in the dropdown listboxes.

How do I get it to do that?

Thanks for your reply!

:)

Code:
Private Function ClearForm()
Dim MyControl As Control

 For Each MyControl In Me.Controls
  If TypeOf MyControl Is TextBox Then
    MyControl.Enabled = True
    MyControl.Visible = True
    MyControl = ""
   ElseIf TypeOf MyControl Is ComboBox Then
    MyControl.Enabled = True
    MyControl.Visible = True
    MyControl.SetFocus
    MyControl.ListIndex = False
  ElseIf TypeOf MyControl Is ListBox Then
    MyControl.Enabled = True
    MyControl.Visible = True
    MyControl.SetFocus
    MyControl.ListIndex = False
   ElseIf TypeOf MyControl Is CheckBox Then
    MyControl.Enabled = True
    MyControl.Visible = True
    MyControl = False
   End If
Next MyControl
End Function
[code]
 
A listbox has a rowsource, not a value. Set listbox row source to null.
 
Excellent suggestion.

I will give it a try.

Thanks for your reply.
 

Users who are viewing this thread

Back
Top Bottom