|
-
Nov 21st, 2018, 08:28 AM
#1
Thread Starter
Fanatic Member
clean controls from form with error
Hi
I'm trying to clear the form using the code below
Code:
Function ClearAll(frm As Form)
Dim ctl As Control
For Each ctl In frm.Controls
Select Case TypeName(ctl) 'ctl.ControlType
Case "TextBox"
ctl.Value = ""
Case "OptionGroup", "ComboBox", "ListBox"
ctl.Value = Null
Case "Checkbox"
ctl.Value = False
'Case ac
End Select
Next
End Function
But return error Runtime error 438

error occurs because my combobox is Style = Dropdown List
-
Nov 21st, 2018, 08:56 AM
#2
Fanatic Member
Re: clean controls from form with error
 Originally Posted by mutley
Hi
I'm trying to clear the form using the code below
Code:
Function ClearAll(frm As Form)
Dim ctl As Control
For Each ctl In frm.Controls
Select Case TypeName(ctl) 'ctl.ControlType
Case "TextBox"
ctl.Value = ""
Case "OptionGroup", "ComboBox", "ListBox"
ctl.Value = Null
Case "Checkbox"
ctl.Value = False
'Case ac
End Select
Next
End Function
But return error Runtime error 438

error occurs because my combobox is Style = Dropdown List
Put "ComboBox" as a seperate case.
then make sure the combobox has a blank item and either set that as "" or set listindex = 0
-
Nov 21st, 2018, 08:58 AM
#3
Re: clean controls from form with error
just clear that error..
you do want all Contols blank
Code:
Option Explicit
Private Sub Command1_Click()
Call clearForm(Me)
End Sub
Public Sub clearForm(ByRef myForm As Object)
On Error GoTo EH
Dim objCtrl As Control
For Each objCtrl In myForm.Controls
If TypeOf objCtrl Is TextBox Then
objCtrl = ""
End If
If TypeOf objCtrl Is CheckBox Then
objCtrl = 0
End If
If TypeOf objCtrl Is ComboBox Then
objCtrl = ""
End If
Next
EH:
If Err.Number = 438 Then
Resume Next
End If
End Sub
Private Sub Form_Load()
Combo1.AddItem "Test"
End Sub
to hunt a species to extinction is not logical !
since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.
-
Nov 21st, 2018, 01:33 PM
#4
Re: clean controls from form with error
To clear a combo with set to drop down list set the listindex to -1
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|