VB Code:
Private Function SaveData(ByVal blnIsCAS As Boolean, ByVal blnIsSent As Boolean, ByVal blnIsNotSent As Boolean) As Boolean
Dim strSQL, strErrMsg As String
Dim cmd As OleDbCommand
Dim cn As OleDbConnection
SaveData = True 'initialize
'Build SQL string based on whether project is CAS.
'Including service date on CAS raises cast error when no date present.
strSQL = "INSERT INTO WhiteSlips "
If blnIsCAS Then
strSQL += "([Database], [ChooseProject], [From], [Subject], [SurveyNumber], [Month], [PatientNumber], [Area/Page], [PatientName], [ComputerNumber], [PatientPhone], [InterviewerNumber], [Message], [Sent], [NotReallySent]) "
Else
strSQL += "([Database], [ChooseProject], [From], [Subject], [SurveyNumber], [Month], [PatientNumber], [Area/Page], [PatientName], [ComputerNumber], [PatientPhone], [InterviewerNumber], [Discharge/ServiceDate], [Message], [Sent], [NotReallySent]) "
End If
strSQL += "VALUES ('"
strSQL += mstrDBName & "', '" & CStr(cboProject.SelectedItem) & "', '" & txtFrom.Text & "', '"
strSQL += txtSubject.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 += "'" & txtMessage.Text & "', " & blnIsSent & ", " & blnIsNotSent & ")"
Else
strSQL += "#" & CDate(txtSvcDate.Text) & "#, '"
strSQL += txtMessage.Text & "', " & 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 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