VB Code:
Private Function SaveData(ByVal blnIsCAS As Boolean, ByVal blnIsSent As Boolean, ByVal blnIsNotSent As Boolean) As Boolean
Dim strSQL, strMsg, strErrMsg As String
Dim cmd As OleDbCommand
Dim cn As OleDbConnection
strMsg = Replace(txtMessage.Text, "'", "''", , , CompareMethod.Text)
SaveData = True 'initialize & strPath
'Build SQL string based on whether project is CAS.
'Including service date on CAS raises cast error when no date present.
strSQL = "INSERT INTO PurpleSlips "
If blnIsCAS Then
strSQL += "([Database], [ChooseProject], [From], [SurveyNumber], [Month], [PatientNumber], [Area/Page], [PatientName], [ComputerNumber], [PatientPhone], [InterviewerNumber], [Message], [Sent], [NotReallySent]) "
Else
strSQL += "([Database], [ChooseProject], [From], [SurveyNumber], [Month], [PatientNumber], [Area/Page], [PatientName], [ComputerNumber], [PatientPhone], [InterviewerNumber], [ServiceDate], [Message], [Sent], [NotReallySent]) "
End If
strSQL += "VALUES ('"
strSQL += mstrDBName & "', '" & CStr(cboProject.SelectedItem) & "', '" & txtFrom.Text & "', "
strSQL += CInt(txtSurNum.Text) & ", '"
strSQL += CStr(cboMonth.SelectedItem) & "', "
strSQL += CInt(txtPatNum.Text) & ", '"
strSQL += txtModName.Text & "', '" & txtPatName.Text & "', "
strSQL += CInt(txtCompNum.Text) & ", '"
strSQL += txtPatPhone.Text & "', "
strSQL += CInt(txtInterviewerNum.Text) & ", "
If blnIsCAS Then
strSQL += "'" & strMsg & "', " & blnIsSent & ", " & blnIsNotSent & ")"
Else
strSQL += "#" & CDate(txtSvcDate.Text) & "#, '"
strSQL += strMsg & "', " & blnIsSent & ", " & blnIsNotSent & ")"
End If
cn = New OleDbConnection(mstrCn)
cmd = New OleDbCommand(strSQL, cn)
strErrMsg = "Please try Send again."
Try
cn.Open()
cmd.ExecuteNonQuery() 'save data
Catch ex As OleDbException 'error opening connection
MsgBox(strErrMsg & vbCrLf & ex.message, MsgBoxStyle.Information, "Error Opening Connection")
SaveData = False
Catch ex As InvalidOperationException 'connection already open or error executing command
MsgBox(strErrMsg & vbCrLf & ex.Message, MsgBoxStyle.Information, "Connection Or Save Error")
SaveData = False
Catch ex As Exception
MsgBox(strErrMsg & vbCrLf & ex.message, MsgBoxStyle.Information, "Error Saving Data")
SaveData = False
Finally
If cn.State = ConnectionState.Open Then
cn.Close()
End If
If SaveData = True Then
mblnDataChanged = False
End If
End Try
End Function