Hi there. I have build a form for data entry. It works just fine, but when I check the table to see what is new there are always lots of blank records interspersed beterrn the correctly filled ones. Im pretty sure that it isnt happening when I click the button on the splash page that sends you to the data entry form.
Here is the code for the button that adds the record.
Anyone see anything in there that would be causing this issue. Its not a huge deal, but a pain in the butt to get rid of the blanks.
-Z
Here is the code for the button that adds the record.
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
'clear all objects
Me.rmENCON.Value = ""
Me.rmDate.Value = ""
Me.rmName.Value = ""
Me.rmInjury.Value = ""
Me.rmComments.Value = ""
Me.Med_Risk.Visible = False
Me.rmMedication.Value = ""
Me.rmLocation.Value = ""
Me.rmVictimstatus.Value = ""
Me.rmType.Value = ""
Me.rmSpecificType.Value = ""
Me.rmPersonInvolved.Value = ""
Me.rmResolved.Value = ""
Me.ResolvedOrPending.Value = ""
Me.rmDateResolved.Value = ""
'send back to main page.
DoCmd.OpenForm "Main_Page"
Else
MsgBox "An Error has occurred, please check and try again"
End If
DoCmd.Close acForm, "Enter_New_Incident"
End Sub
Anyone see anything in there that would be causing this issue. Its not a huge deal, but a pain in the butt to get rid of the blanks.
-Z