Full Version: Clearing Form Fields/Attching a Report
UtterAccess Forums > Microsoft® Access > Access Forms
GirlGeek
Hi, All.
I have been working on a form that is very nearly complete except for two issues.
) Is there a command button I can add that will clear all fields in the form? I have noticed that after one record is saved, the old data remains, which can be very confusing.
2) I need to be able to click a command button that will automatically attach a report to an e-mail and send it off. I have been able to get the e-mail button to work but cannot get the report to attach.
Any ideas would be GREATLY appreciated.
Thanks.
GG
mrspruitt
Hi,
Regarding issue 1, what I do is reset my fields in the On Current Event.
Me.FieldName1 = Null (or empty or " ")
.
.
.
Me.FieldNamen= Null(or emptyor " ")
There may be a more elegant way that someone could share. But until then I hope this helps!
GirlGeek
I'm sorry, but I think I'm too dumb to get this. On Current Event? Is that a form toggle?
mrspruitt
That is the event that triggers when you move from the current record to the next record. Go to the properties of your form. There is an event tab. Go to On Current. Select Event Procedure from the drop down list. Click the button with the three dots ... to the far right on the On Current line. This will open the VB editor to the On Current event. This is where you will type the code to reset your fields. I have attached a screen shot.
GirlGeek
Would you be kind enough to attache a screen shot of the actual code? I do not know VB at all and am exhausted in trying to figure this whole thing out. I tried what you told me to do but ended up with an error. Phooey. :-(
hat, for example, does the "Me" mean in this? Me.FieldName1 And is FieldName1 = to the actual field or the label?
Sorry. I am pretty new to this level of Access programming.
GG
Tidepooler
The "Me" part is what you put in the code to just refer only to the form that you are currently dealing with. You should type that exactly as it is in the code.
But the part that says "FieldName1" -- you need to substitute in the name of your own field names there.
So, let's say that you have a text box on your form that someone is going to put a value in. What is it called? You can find out by clicking on the text box in design view, then going to the View menu at the top, and selecting Properties. Then, go to the "Other" tab, and look at the Name. Whatever it shows there is what you substitute in for the "FieldName1" in the above code. To make it easier on yourself (in terms of remembering what the different controls on your form are named), you can change the name if you want, to something easier to remember.
So, where mrspruitt above said to type: Me.FieldName1 = Null (or empty or " ")
you would type in Me.FieldName1 = Null
where FieldName1 is the name of your first control that you want to clear out.
You'll have to repeat that for each and every control you have, substituting in the next control name on your form, and so on until you've put that line in for each and every control on your form.
See if that works for you! Good luck.
GirlGeek
Thank you! I will try this when I get to work. Wondering, though, is there a way to clear all the fields when a command button is clicked? I have an "Add Record" command button but it will not clear the fields.
Thanks so much for your help!
Tidepooler
Yes, you can just make a command button, then select in in design view, and go to the View Menu and select properties. Then, go to the Events Tab. Look for one in the list called "OnClick". Click in the box next to that, and then click on the little ... symbol next to it, and select Code Builder from the resulting menu.
It will then put you into the Visual Basic window behind Access. You should see something like this:
CODE
Private Sub cmd1_OnClick()
End Sub

Where, cmd1 is the name of the command button you just created.
Put your cursor in between the two lines of code there, and type in what was suggested above.
Then, test it out and see how it works!
Good luck.
GirlGeek
Sigh. Okay, so I tried this and it is giving me errors. I think it is giving me errors because I am populating various fields that are static by using a Combo key and Column references.
For example, one field is "named" CellLead but it =Combo0.Column(2).
Is this why I'm erring out? Can anybody help?
Thanks.
Tidepooler
It depends what you mean by "named". If you mean "named", as in the text that is in the field in design view as it shows on the form, then it is important for you to distinguish that this is not the name of the field. The text that appears in the field in form design view is usually referencing the field in the table that the particular form field is "bound" to -- meaning whatever is typed into the form by the user will go into the "bound" field in the table.
The true name of your combo box is shown in the Properties window, as I indicated above. It seems to me, the way you are referencing that field above, it's true name is "Combo0".
If I were you, I would try using the Me.Combo0.Value = Null and see if that works.
Unless Combo0 isn't the true name and it is actually something else.
Orealize its frustrating -- I'm having my own frustrations here too. But these folks are really helpful, so don't give up! Keep posting and you'll get there.
GirlGeek
YIPPEE! I got it!!!!!!!! BY MYSELF! (Sort of... ;-))
simply omitted all fields that were populated, set a default to come up with "Choose Cell", and cleared the rest! YAYAYAYAYAY! Thanks everyone! THANKYOU!
Now, if I could just get that darned EMAIL thing working, I'd be SET! :-)
Tidepooler
Great to hear, GirlGeek! Congratulations!
GirlGeek
Maybe I spoke too soon (ready to weep). The fields are indeed clearing but it appears as if nothing is populating my table, either!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
It appears to take the first entry and that is it. I am so sick of this report I could SCREAM!
mrspruitt
Curlie,
If you need to reset all of the fields in the form then you could use the For Each Loop and loop through all of the controls on the form. See this thread for an example of how it used to check if fields are left blank in a form. You can adapt it to init the fields.
GirlGeek
Can you hear me crying? ARGH!
My fields quit saving to my table. SO.... I took this suggestion:
DoCmd.Save saves the *form* and not the record. To do this, you need either on of these two lines of code:
Me.Dirty=False
Oput it in the properties of the last field of the form. NOW, I get an error message. WAH!
I've attached a screen shot.
PLEASE HELP!
GirlGeek
Sigh. I found it. How to change it.
ads. I sure am learning Access and VB the HARD WAY! :-)
mrspruitt
Could you send the code?
GirlGeek
Okay. So.
set the me.fieldname=null in all the fields I needed cleared. However, on the combo0 field, I indicated that this = "Choose Field". I had already added this to the original table and it was working very nicely until something happened.
Now, when I choose the Clear Fields button and click on the drop-down, i get the error: The value you entered isn't valid for this field.
Keep in mind, I have changed nothing in that area, the field is set appropriately (I think) and once i ok this, it lets me choose a cell.
Any ideas?
GirlGeek
Here is the code for the whole form. It means little to me. :-(
Private Sub AddRecord_Click()
On Error GoTo Err_AddRecord_Click
DoCmd.GoToRecord , , acNewRec
Exit_AddRecord_Click:
Exit Sub
Err_AddRecord_Click:
MsgBox Err.Description
Resume Exit_AddRecord_Click

End Sub
Private Sub RefreshDate_Click()
On Error GoTo Err_RefreshDate_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
Exit_RefreshDate_Click:
Exit Sub
Err_RefreshDate_Click:
MsgBox Err.Description
Resume Exit_RefreshDate_Click

End Sub
Private Sub Command67_Click()
On Error GoTo Err_Command67_Click
Dim stDocName As String
stDocName = "rptDaily Target Report"
DoCmd.SendObject acSendReport, "rptDaily Target Report", acFormatHTML, "psimer@filterminder.com"
DoCmd.SendObject acSendReport, "rptDaily Target Report", acFormatHTML, "khemann@filterminder.com"
Exit_Command67_Click:
Exit Sub
Err_Command67_Click:
MsgBox Err.Description
Resume Exit_Command67_Click

End Sub
Private Sub E_MailReport_Click()
End Sub
End Sub
Private Sub Command89_Click()
End Sub
Private Sub Command90_Click()
Me.Combo0 = "Choose Cell"
Me.HoursCharged = Null
Me.Date_Reporting_For_ = Null
Me.OutputActual = Null
Me.OReasonforVariance = Null
Me.ManningActual = Null
Me.MReasonforVariance = Null
Me.MPGReasonforVariance = Null
Me.ScrapActualNumber = Null
Me.SNumberReasonforVariance = Null
Me.SPercentReasonforVariance = Null
End Sub
Private Sub S_ReasonforVariance_Click()
End Sub
Private Sub Save_Record_Click()
On Error GoTo Err_Save_Record_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Exit_Save_Record_Click:
Exit Sub
Err_Save_Record_Click:
MsgBox Err.Description
Resume Exit_Save_Record_Click

End Sub
Private Sub Add_Record_Click()
On Error GoTo Err_Add_Record_Click
DoCmd.GoToRecord , , acNewRec
Exit_Add_Record_Click:
Exit Sub
Err_Add_Record_Click:
MsgBox Err.Description
Resume Exit_Add_Record_Click

End Sub
Private Sub Refresh_Click()
On Error GoTo Err_Refresh_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
Exit_Refresh_Click:
Exit Sub
Err_Refresh_Click:
MsgBox Err.Description
Resume Exit_Refresh_Click

End Sub
Private Sub E_Mail_Report_Click()
On Error GoTo Err_E_Mail_Report_Click
Dim stDocName As String
stDocName = "DailyTargetReport"
DoCmd.SendObject acReport, stDocName
Exit_E_Mail_Report_Click:
Exit Sub
Err_E_Mail_Report_Click:
MsgBox Err.Description
Resume Exit_E_Mail_Report_Click

End Sub
Private Sub Form_AfterUpdate()
End Sub
Private Sub Form_Load()
End Sub
Private Sub SPercentReasonforVariance_BeforeUpdate(Cancel As Integer)
End Sub
Private Sub SPercentReasonforVariance_Change()
End Sub
Private Sub SaveRecord_Click()
On Error GoTo Err_SaveRecord_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Exit_SaveRecord_Click:
Exit Sub
Err_SaveRecord_Click:
MsgBox Err.Description
Resume Exit_SaveRecord_Click

End Sub
mrspruitt
It sounds like you want the text "Choose Field" to appear in the Combo0 box for each new record. I would make it the default value. You can do that in properties. I have included a screen shot in case you need it.
GirlGeek
I did that, but I get the error message now (I didn't before... I don't know what has changed.)
The data that is being populated in the forms is not saving to the table, either... only the information that the person is actually inputting.
I'm exhausted and feeling dumber by the second.
mrspruitt
1) RunCommand replaced DoMenuItem to execute menu or toolbar commands you may want to invesitgate using it instead.
MSDN library
2) I don't understand why you are clearing the form with a button and then moving to a new record with a different button. I suggested earlier that you place the init of your fields in the Form OnCurrent Event. I believe that is the event that triggers when you move to a new record. It doesn't look like you did that.
3) If you do not have any proprietary info in your db zip it up and attach it.
GirlGeek
Sigh. Again. I will, on Monday. I'm going home for the day. Thank you for your help.
ired GG
GirlGeek
Okay. Okay. Okay. It's Monday morning and my head is clearer and I think I have nearly everything working right except for one last critical component.
My form has various fields that populate with static data based on a choice from a drop down box. In addition, there are approximately 3 fields that need to be filled in by the user.
What I am finding is that the information that is added by the user is the only information that is then saved to a table. I need all of the information to be saved to a table for future reference, queries, etc.
Can anybody shed some light as to why this might be happening??
Thanks.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.