Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Code Help

Posted on 2006-07-04
6
Medium Priority
?
514 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 80 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 240 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 80 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
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Suggested Courses

963 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