Solved

Code Help

Posted on 2006-07-04
6
488 Views
Last Modified: 2012-06-27
Hi:

I'm using the following code behind a Save button on an unbound form. It works okay but I want it to clear the form (boxes) after save. The "DoCmd.RunCommand acCmdDataEntry" usually does that for me but in this case it is not.

Private Sub LogDataFormSave_Click()

Set db = CurrentDb
Set rst = db.OpenRecordset("Data")
With rst
    .AddNew
    !StudentFullName = Me.StudentFullName
    !Staff1 = Me.Staff1
    !Staff2 = Me.Staff2
    !Staff3 = Me.Staff3
    !Staff4 = Me.Staff4
    !Staff5 = Me.Staff5
    !cDate = Me.cDate
    !Reason1 = Me.Reason1
    !Reason2 = Me.Reason2
    !Type1 = Me.Type1
    !Type2 = Me.Type2
    !Type3 = Type3
    !TimeInI = Me.TimeInI
    !TimeOutI = Me.TimeOutI
    !TimeInR = Me.TimeInR
    !TimeOutR = Me.TimeOutR
    !Room = Me.Room
    !Door = Me.Door
    !ConstantContact = Me.ConstantContact
    !Checks = Me.Checks
    .Update
End With

rst.Close

DoCmd.RunCommand acCmdDataEntry

End Sub

Thanks,

whitesandsbeach
0
Comment
Question by:whitesandsbeach
6 Comments
 
LVL 44

Assisted Solution

by:Arthur_Wood
Arthur_Wood earned 20 total points
ID: 17037402
try this:

Private Sub LogDataFormSave_Click()

Set db = CurrentDb
Set rst = db.OpenRecordset("Data")
With rst
    .AddNew
    !StudentFullName = Me.StudentFullName
    !Staff1 = Me.Staff1
    !Staff2 = Me.Staff2
    !Staff3 = Me.Staff3
    !Staff4 = Me.Staff4
    !Staff5 = Me.Staff5
    !cDate = Me.cDate
    !Reason1 = Me.Reason1
    !Reason2 = Me.Reason2
    !Type1 = Me.Type1
    !Type2 = Me.Type2
    !Type3 = Type3
    !TimeInI = Me.TimeInI
    !TimeOutI = Me.TimeOutI
    !TimeInR = Me.TimeInR
    !TimeOutR = Me.TimeOutR
    !Room = Me.Room
    !Door = Me.Door
    !ConstantContact = Me.ConstantContact
    !Checks = Me.Checks
    .Update
End With

rst.Close

DoCmd.RunCommand acCmdDataEntry

ClearMe

End Sub

Private sub ClearMe()
   Dim ctl as Control

   for each ctl in Me.Controls
      If TypeOf ctl is TextBox then
            ctl.setfocus
            ctl.text = ""
      end if
   Next
End Sub

Only works on UNBOUND controls.

AW
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 60 total points
ID: 17037412
if u set the TAG property to contain some text, u can then do this

dim ctl as control
for each ctl in Me.Controls
    if ctl.Tag = "CLEARME" then ctl.Value = ""
next ctl


in this case, in design view, I set the TAG property for all fields concerned to have the value CLEARME
0
 
LVL 3

Assisted Solution

by:atherh
atherh earned 20 total points
ID: 17037417

'Place this function in your Module
'========================
Function fClearFields(frm As Form) As Boolean

' Clear All Form Controls (using name)
Dim ctl As Object
For Each ctl In frm.Controls
 
    If TypeOf ctl Is CheckBox Then
        If ctl.Enabled = True Then
           ctl.Value = False
        End If
    ElseIf TypeOf ctl Is TextBox Then
        If ctl.Enabled = True Then
                 ctl.Value = ""
        End If
    ElseIf TypeOf ctl Is ComboBox Then
        If ctl.Enabled = True Then
            ctl.SetFocus
            ctl.Value = ""
        End If
    End If
 
         
Next

  fClearFields = True
 
End Function

'Copy your code from here
'--------------------------------------------
Private Sub LogDataFormSave_Click()

Set db = CurrentDb
Set rst = db.OpenRecordset("Data")
With rst
    .AddNew
    !StudentFullName = Me.StudentFullName
    !Staff1 = Me.Staff1
    !Staff2 = Me.Staff2
    !Staff3 = Me.Staff3
    !Staff4 = Me.Staff4
    !Staff5 = Me.Staff5
    !cDate = Me.cDate
    !Reason1 = Me.Reason1
    !Reason2 = Me.Reason2
    !Type1 = Me.Type1
    !Type2 = Me.Type2
    !Type3 = Type3
    !TimeInI = Me.TimeInI
    !TimeOutI = Me.TimeOutI
    !TimeInR = Me.TimeInR
    !TimeOutR = Me.TimeOutR
    !Room = Me.Room
    !Door = Me.Door
    !ConstantContact = Me.ConstantContact
    !Checks = Me.Checks
    .Update
End With

rst.Close

DoCmd.RunCommand acCmdDataEntry

'Add here this line
'-----------------------
If fClearFields(Me) = True Then

End If
'-----------------------
End Sub
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 44

Expert Comment

by:GRayL
ID: 17037476
According to:  www.mvps.org/access/forms/frm0031.htm  -  You should be referring to all your form values as Me! not Me.

VBHelp (Ctl-G), Answer Wizard - type - RunCommand - suggests you could try:

Me.RunCommand acCmdDataEntry  -  in place of your DoComd. line
0
 
LVL 3

Expert Comment

by:atherh
ID: 17037552
I have given the code which is working fine for me here in my application . :)
0
 
LVL 44

Expert Comment

by:GRayL
ID: 17037601
How about the latter suggestion to clear the form.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question