Clear form fields after saving

I want my form to clear its field after saving. The code that I have so far is not functioning properly:


Private Sub cmdSav_Click()
 
 
    Dim conCars As ADODB.Connection
    
    Set conCars = Application.CurrentProject.Connection
    
 
    conCars.Execute "INSERT INTO Monitor(SerialNo, ManufacturerSerialNo, Make, " & _
                    "Model, DatePurchased, WarrantyPeriod, MonitorSize, " & _
                    "AssignedOfficer) VALUES('', '', '', '', '', '', '', '')"
 
      
    conCars.Close
    DoCmd.GoToRecord , , acNewRec
    Set conCars = Nothing
End Sub

Open in new window

LEBAONEMUNAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

silemoneCommented:
why not pass null as as value and when pulling, use isNull(field, '')
0
silemoneCommented:
by the way, more than likely if its not working, it's due to an sql error...try to place in a string first and debug and put a breakpoint at that string and see if maybe it's leaving off an ')' or something...copy and paste result and test directly in access
0
peter57rCommented:
The only line of the code shown which could have anything to do with a form is the line:
DoCmd.GoToRecord , , acNewRec

This will only have any effect if you are using a bound form, since there is no 'new record' concept for an unbound form.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

LEBAONEMUNAuthor Commented:
I have a 5-tabs form with each tab having a subform that have a table as its source object. Each tab a save button and there is an overall save button. Now I want to make sure each time I press save form fields are cleared. Its not an sql error because it saving fine only that its not clearing fileds.
0
peter57rCommented:
If the form/subform is bound the only way you can 'clear' the textboxes is to move to a new record.
For a bound form there must always be a record visible - either an existing saved record or a new record.
0
LEBAONEMUNAuthor Commented:
All the subforms are bound. How can I use a for....next loop to achieve this. I have a feeling that can be done through that route..
0
peter57rCommented:
I'm not clear what you are asking- are you asking can you loop through a list of subreports moving each one to a new record?
0
LEBAONEMUNAuthor Commented:
One way to clear unbound forms is to use a for....next loops. So is it not possible to use this, in this case. I know I said each subform is bound because its 'source object' is pointing to the tables. But again is it possible to loop through each subform moving each one to a new record.
0
LEBAONEMUNAuthor Commented:
Ok, I thought that since DoCmd.GoToRecord,,acNewRec wont do it for me I could use the following code. Would it work.
For Each ctl In Me.Controls
    If (ctl.ControlType = acTextBox) Then
        ctl.Value = Null
    End If
Next ctl

Open in new window

0
peter57rCommented:
No it will not work.

If you are using a bound form, setting the control value is changing the visible record.

For each of your form you can move to a new record after adding a record by usib=ng the afterinsert event procedure.

You would use the same code in every form:

Private Sub Form_AfterInsert()
DoCmd.GoToRecord acDataForm, Me.Name, acNewRec
End Sub
0
LEBAONEMUNAuthor Commented:
Thanx for your response. But I cant figure out what Name would be in thi case (Me.Name, acNewRec)
0
peter57rCommented:
It is literally Name
0
LEBAONEMUNAuthor Commented:
I have put the given code in each form. But when I get to the main form after inserting the records nothing happens still.
0
peter57rCommented:
If you have done as I described, as you save each new record in a subform you should move to a new empty record in that subform.
0
LEBAONEMUNAuthor Commented:
I chose to intead use the code below for each control in the form and it works fine for me at the moment just have to fine-tune it.
Forms!Computer!TabCtl0.Pages!CPUInfo.Controls!cpu.Controls!Speed.Text = ""

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.