If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
the intracacies of clearing a form
Hi guys,
I have been trying to figure out the best practices for clearing a form that already has the record ID autokey entered (want to keep this) I found this snippet: Dim ctl As Control For Each ctl In Me.Controls If (ctl.ControlType = acTextBox) Then If (Left$(ctl.ControlSource, 1) "=") Then ctl.Value = "" End If End If Next ctl but, I do have some required fields and this throws an error for these fields needing to be not null. also, what about subforms? anybody have any good experience with this, Im sure others would appreciate it too/ Cheers, David |
#2
|
|||
|
|||
the intracacies of clearing a form
Hi
I'd do the following: Set the tag property of all the fields i'd like cleared to say CLEAR (including on any subforms). Then add the following sub: Private Sub ClearControls(frm As Form) Dim ctl As Control For Each ctl In frm.Controls If ctl.Tag = "CLEAR" Then If ctl.DefaultValue "" Then ctl = ctl.DefaultValue Else ctl = Null End If End If Next ctl End Sub this can be run by the following for a main form: Call ClearControls(Me) or this for a subform (in a control called sfcSubForm): Call ClearControls(Me!sfcSubForm.Form) hth Chris -----Original Message----- Hi guys, I have been trying to figure out the best practices for clearing a form that already has the record ID autokey entered (want to keep this) I found this snippet: Dim ctl As Control For Each ctl In Me.Controls If (ctl.ControlType = acTextBox) Then If (Left$(ctl.ControlSource, 1) "=") Then ctl.Value = "" End If End If Next ctl but, I do have some required fields and this throws an error for these fields needing to be not null. also, what about subforms? anybody have any good experience with this, Im sure others would appreciate it too/ Cheers, David . |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Searching Records | Melissa Lambino | New Users | 6 | July 20th, 2004 04:51 AM |
Clearing Values in a form | Haji | Using Forms | 2 | July 9th, 2004 10:49 PM |
Modal form | Praveen Manne | Using Forms | 1 | July 6th, 2004 10:49 PM |
surely a form with a ListBox can be used in a query? | 1.156 | Running & Setting Up Queries | 14 | June 2nd, 2004 04:54 PM |
Form Doesn't Go To New Record | Steve | New Users | 15 | May 16th, 2004 04:33 PM |