I am building a new form, Im fairly new to form development. The idea is that there is a main splash page form where the user can hit a button to "add a new record" (code below):
When you click on "add new record" the next form (unbound) with all the combo/texboxes opens fine and it does add the record correctly when I hit the "add new incident" button (code below)
So this button adds the record and sends me back to the main page, but when you click the "add new record" button to go back to the data entry form, the data from the previous entry is still in all of the fields. I want the form to be blank each time you go to it, but I have as of yet been unable to figure out how. I have tried many of the suggestions on threads that seem to describe the same problem.
If anyone could help that would be super
-Z
Code:
Private Sub Command0_Click()
On Error GoTo Err_Command0_Click
DoCmd.OpenForm "Enter_New_Incident"
DoCmd.GoToRecord acForm, "Enter_New_Incident", acNewRec
Exit_Command0_Click:
Exit Sub
Err_Command0_Click:
MsgBox err.Description
Resume Exit_Command0_Click
End Sub
When you click on "add new record" the next form (unbound) with all the combo/texboxes opens fine and it does add the record correctly when I hit the "add new incident" button (code below)
Code:
Private Sub rmAddIncident_Click()
Dim err As Integer
Dim cnn1 As ADODB.Connection
Dim Risk_Data As ADODB.Recordset
Dim strCnn As String
'Check that all fields are filled in
rmENCON.SetFocus
If rmENCON.Text = "" Then
err = err + 1
MsgBox "Please fill in the ENCON number." & err
End If
rmName.SetFocus
If rmName.Text = "" Then
err = err + 1
MsgBox "Please fill in the name of the person affected by the incident."
End If
rmDate.SetFocus
If rmDate.Text = "" Then
err = err + 1
MsgBox "Please fill in the date the incident occured."
End If
rmInjury.SetFocus
If rmInjury.Text = "" Then
err = err + 1
MsgBox "Please specify the degree of injury."
End If
rmComments.SetFocus
If rmComments.Text = "" Then
err = err + 1
MsgBox "Please briefly describe the incident in the comments box."
End If
rmResolved.SetFocus
If rmResolved.Text = "" Then
err = err + 1
MsgBox "Please briefly summarize the follow-up."
End If
rmVictimstatus.SetFocus
If rmVictimstatus.Text = "" Then
err = err + 1
MsgBox "Please fill in the Victim status."
End If
rmLocation.SetFocus
If rmLocation.Text = "" Then
err = err + 1
MsgBox "Please fill in the location the incident took place."
End If
rmType.SetFocus
If rmType.Text = "" Then
err = err + 1
MsgBox "Please incicate the type of incident that occured."
End If
rmSpecificType.SetFocus
If rmSpecificType.Text = "" Then
err = err + 1
MsgBox "Please incicate the specific type of incident that occured."
End If
'if no errors insert data
If err < 1 Then
' Open a connection.
Set cnn1 = New ADODB.Connection
mydb = "G:\Admin\Ceo\Human Resources\RISKMGMT\Inhouse data\Risk Database\Inhouse Data.mdb"
strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mydb
cnn1.Open strCnn
' Open Risk_Data table.
Set Risk_Data = New ADODB.Recordset
Risk_Data.CursorType = adOpenKeyset
Risk_Data.LockType = adLockOptimistic
Risk_Data.Open "Risk_Data", cnn1, , , adCmdTable
'get the new record data
Risk_Data.AddNew
Risk_Data!ENCON = rmENCON
Risk_Data!Name = rmName
Risk_Data!Date = rmDate
Risk_Data!Injury = rmInjury
Risk_Data![Incident Comments] = rmComments
Risk_Data![Medication Risk] = Med_Risk
Risk_Data![Medication/Equipment] = rmMedication
Risk_Data![Victim Status] = rmVictimstatus
Risk_Data!Location = rmLocation
Risk_Data!Type = rmType
Risk_Data![Specific Type] = rmSpecificType
Risk_Data![Phys/Empl/Pt Involved] = rmPersonInvolved
Risk_Data![Follow-up Summary] = rmResolved
Risk_Data![Resolved or Pending] = ResolvedOrPending
Risk_Data![Date Resolved] = rmDateResolved
Risk_Data.Update
'Show the newly added data.
MsgBox "Incident #: " & Risk_Data!ENCON & " has been successfully added"
'close connections to DB.
Risk_Data.Close
cnn1.Close
'send back to main page.
DoCmd.OpenForm "Main_Page"
Else
MsgBox "An Error has occurred, please check and try again"
End If
End Sub
So this button adds the record and sends me back to the main page, but when you click the "add new record" button to go back to the data entry form, the data from the previous entry is still in all of the fields. I want the form to be blank each time you go to it, but I have as of yet been unable to figure out how. I have tried many of the suggestions on threads that seem to describe the same problem.
If anyone could help that would be super

-Z