New Record Command Button

S

Serendipity

I have a form that I created a command button to allow the user to enter
another inspection form from the field. While it clears the majority of the
information from the form, the check boxes that were chosen in the previous
inspection do not reset. If you leave them checked, they do not store in the
new inspection as being chosen, but it confusing for the end user to see
things checked. The form is set to data entry. Each of these checkboxes have
the following VBA code with changes based upon the item chosen. I have also
included the VBA code on the command button. These check boxes are to default
as unchecked as we are only tracking when the condition exists. How do I get
the checkboxes to default to unchecked each time a new inspection is to be
entered? Also, if the form is closed and reopened, they are unchecked, so it
is only a problem when the end user is entering multiple inspections without
closing the form.

Thanks for your help.
Serendipity

VBA on the Check Box:
Private Sub Check96_AfterUpdate()
Dim strSQL As String

If Me.Check96 = True Then
strSQL = "INSERT INTO tblInspectionReportItems " & _
"(InspectionReportID, ReportDetailItemID,UFE) " & _
"VALUES (" & Me.txtInspectionReportID & ", " & _
CLng(Me.Check96.Tag) & ", '" & _
Forms!frmLogin!txtUserName & "') "
Else
strSQL = "DELETE * FROM tblInspectionReportItems " & _
"WHERE InspectionReportID = " & Me.txtInspectionReportID & _
" AND ReportDetailItemID = " & CLng(Me.Check96.Tag) & ";"
End If

CurrentDb.Execute strSQL

End Sub

VBA on the Command Button:



Private Sub CMDEnterNewRoofInspection_Click()
On Error GoTo Err_CMDEnterNewRoofInspection_Click


DoCmd.GoToRecord , , acNewRec

Exit_CMDEnterNewRoofInspection_Click:
Exit Sub

Err_CMDEnterNewRoofInspection_Click:
MsgBox Err.Description
Resume Exit_CMDEnterNewRoofInspection_Click
 
D

Dennis

I put code in the command button section to explicitly clear all fields. Of
course, that's for unbound forms. For bound forms, it's automatic.
 
S

Serendipity

What would that look like? I am new to VBA, and struggle with it. I am unable
to find anything in the 3 books I have to do this?
 
D

Dennis

Well, let's say you have two textbox fields and three checkbox fields. With
that in mind, in the VBA code behind the Event, you'd code something like
this:

Me.TextBox1 = ""
Me.TextBiox2 = ""
Me.Checkbox1 = 0
Me.Checkbox2 = 0
Me.Checkbox3 = 0

Zero is False, Unchecked, etc. The code above, modified for your field
names, should work perfectly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top