A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

the intracacies of clearing a form



 
 
Thread Tools Display Modes
  #1  
Old July 28th, 2004, 12:42 AM
dp
external usenet poster
 
Posts: n/a
Default 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  
Old July 28th, 2004, 10:04 AM
Chris Large
external usenet poster
 
Posts: n/a
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

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


All times are GMT +1. The time now is 05:35 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.