Solved

Code Help

Posted on 2006-07-04
6
480 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
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…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

776 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