•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Visual Basic 4 / 5 / 6 section within the Software Development category of DaniWeb, a massive community of 425,874 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,362 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums
Clearing Controls & Forms in Access (VBA)
---- start of revised code ---- Private Sub cmdClearCriteria_Click() Dim ctl As Control For Each ctl In Me.Controls Select Case ctl.ControlType Case acTextBox, acComboBox, acListBox, acCheckBox If ctl.ControlSource = "" Then ctl.Value = Null End If Case Else End Select Next ctl End Sub '---- end of revised code ---- 'OR '*********** CLEAR FORM FIELDS CODE *********************** Sub Clear_Form() Dim X As Control For Each X In Me.Controls If TypeOf X Is TextBox Then X = Null End If Next X End Sub '************************************************************ OR '*********************************************** Sub ClearFormText(frm As Form) Dim ctl As Control For Each ctl In frm.Controls If ctl.ControlType = acTextBox Then ctl.Value = "" End If Next ctl End Sub Call the code from any event with the following syntax: ClearFormText Me The 'Me' keyword will pass in a reference to the current form and the code will clear all text boxes. '********************************************
Comments (Newest First)
colinnwn | Newbie Poster | Nov 12th, 2007
•
•
•
•
When I try any of the above, I get runtime error 2448 "you can't assign a value to this object".
The object is
ctl.Value = Null or X = Null or ctl.value=""
Does anyone have a thought on why it doesn't work for me? Or are there any other ways to clear all fields on a form?
Thanks.
The object is
ctl.Value = Null or X = Null or ctl.value=""
Does anyone have a thought on why it doesn't work for me? Or are there any other ways to clear all fields on a form?
Thanks.
samershalha | Newbie Poster | Feb 13th, 2006
•
•
•
•
thank for the beautifull code
Post Comment
•
•
•
•
DaniWeb Marketplace (Sponsored Links)