Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clearing a Form 2

Status
Not open for further replies.

rkottke

Technical User
Aug 13, 2001
6
US
I would like to use a form as a template so when I enter data and a commit button is used, the data entered is saved and then the form is cleared to zero and/or nulled. Is this possible? If so, how? This is what I have so far...

Private Sub Command172_Click()
'Add record to sub form
DoCmd.OpenQuery ("Query1"), acViewNormal
Dim rst As Recordset

DoCmd.OpenQuery ("Query2"), acViewNormal

DoCmd.OpenQuery ("Query3"), acViewNormalDo
DoCmd.OpenForm "Form", acNormal


On Error GoTo Err_Command172_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Form"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command172_Click:
Exit Sub

Err_Command172_Click:
MsgBox Err.Description
Resume Exit_Command172_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
End Sub

Any advice would be greatly appreciated!!!

Thanks!
 
When I turned the above mentioned property to yes, my detail fields went blank. Help!!
 
My suggestion is that you save the data with the DoCmd.OpenQuery statements then call a function that would clear all of the fields on the form or set them to zero.

Private Sub Command172_Click()
DoCmd.OpenQuery ("Query1"), acViewNormal
DoCmd.OpenQuery ("Query2"), acViewNormal
DoCmd.OpenQuery ("Query3"), acViewNormal
Call ResetForm

end sub

Private Sub ResetForm()
dim ctl as Control

for each ctl in me.controls
if typeof ctl is Textbox then
'Place a test for the textbox to determine if it will hold text or numeric values and set the controls to vbNullstring or 0, respectively.
end if
if typeof ctl is Checkbox then
ctl = false
end if
'Keep checking for the different controls on your form
next

end sub

This is a simple routine that just scrolls through the form's controls and places a new value into them. It takes virtually no time to complete as well. And you don't have to open your form all over again (which is what I thought you were doing with the last piece of your code).

I also noticed that in your sample code, you declare rst as a recordset but you don't use it, if you don't plan to use it, its best to take it out of the routine.

Hope that helps.

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top