Solved

Code Help

Posted on 2006-07-04
6
496 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: 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!

 
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

Industry Leaders: 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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

730 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