Solved

Code Help

Posted on 2006-07-04
6
463 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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)

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now