Code:
Public Function AddToConsults() As Boolean
AddToConsults = True
Dim RSSetName As String
Dim RSSetUser As String
Dim RSSetAccess As String
Dim RSSetVerify As String
Dim RSSetSave As String
Dim RSReceiveName As Recordset
Set RSReceiveName = CurrentDb.OpenRecordset("SELECT VHALogin, Fname, Lname, VistaAccess, VistaVerify, SaveVistaLogin FROM tblEmployees WHERE (tblEmployees.[VHALogin]) = '" & GetUserName & "'")
RSSetName = RSReceiveName!Fname & " " & RSReceiveName!Lname
RSSetUser = RSReceiveName!VHALogin
RSSetSave = RSReceiveName!SaveVistaLogin
If Not IsNull(RSReceiveName!VistaAccess) Then
RSSetAccess = RSReceiveName!VistaAccess
RSSetVerify = RSReceiveName!VistaVerify
End If
Dim sendName As Variant
Dim AddComment As String
Dim dbs As Database, rsConsults As Recordset
Dim Reflection As Object
Dim Rst As Recordset
Dim strSQL, tempCheck As String
Dim tempChkNeum, tempDelNuem, tmPause As Integer
Dim blnMove, blncheck, blnStopped As Boolean
Set dbs = CurrentDb
Dim FromForm As String
FromForm = Forms!frmToChart.Form!CN
Set rsConsults = dbs.OpenRecordset("SELECT Scheduler_Sheet.ConsultNumber, Scheduler_Sheet.LastName, Scheduler_Sheet.FirstName, Scheduler_Sheet.SSN, Scheduler_Sheet.Clinic, Scheduler_Sheet.ConsultTitle, Scheduler_Sheet.Program FROM Scheduler_Sheet WHERE (Scheduler_Sheet.[ConsultNumber]) = " & FromForm & "")
On Error GoTo Nosession
Set Reflection = GetObject("R2WIN")
rsConsults.MoveFirst
'Do Until rsConsults.EOF
On Error GoTo 0
With Reflection
If InStr(Reflection.GetText(0, 0, 2, 29), Format(Forms!frmToChart.Form!SSN, "000-00-0000")) > 0 Then
.transmit "cv"
.transmit Chr(13)
Pause (0.2)
.transmit "ss"
.transmit Chr(13)
Pause (0.2)
Else
If InStr(Reflection.GetText(0, 0, 23, 80), "Select: Quit//") > 0 Then
.transmit "SP"
.transmit Chr(13)
Pause (0.2)
ElseIf InStr(Reflection.GetText(0, 0, 23, 80), "Select Patient:") > 0 Then
Else
Call LogInToVista
End If
If InStr(Reflection.GetText(0, 0, 23, 80), "Select Non VA Care Authorization Main Menu Option:") > 0 Then
.transmit "^Consult Service Tracking"
.transmit Chr(13)
Pause (0.45)
ElseIf InStr(Reflection.GetText(0, 0, 23, 80), "Select Fee Basis Main Menu Option:") > 0 Then
.transmit "^Consult Service Tracking"
.transmit Chr(13)
Pause (0.45)
ElseIf InStr(Reflection.GetText(0, 0, 23, 80), "Select Consult User Menu Option:") > 0 Then
.transmit "^Consult Service Tracking"
.transmit Chr(13)
Pause (0.45)
End If
If InStr(Reflection.GetText(0, 0, 23, 80), "Select Patient:") > 0 Then
.transmit rsConsults!SSN 'ssn
.transmit Chr(13)
Pause (2.5)
If InStr(Reflection.GetText(0, 0, 23, 80), "... press RETURN to continue ...") > 0 Then
.transmit Chr(13)
Pause (0.4)
End If
Else
If InStr(Reflection.GetText(0, 0, 22, 80), "Select Patient:") > 0 Then
.transmit rsConsults!SSN 'ssn
.transmit Chr(13)
Pause (0.45)
Else
AddToConsults = False
MsgBox "I did not land on the SSN screen, please help fix me!"
.Connected = False
Exit Function
End If
End If
'******FLAGS
If InStr(Reflection.GetText(0, 0, 23, 80), "Are you sure you wish to continue (Y/N)?") > 0 Then
.transmit "y"
.transmit Chr(13)
Pause (2.1)
End If
If InStr(Reflection.GetText(0, 0, 23, 80), "Do you want to continue processing this patient record? No//") > 0 Then
.transmit "y"
.transmit Chr(13)
Pause (2#)
End If
If InStr(Reflection.GetText(0, 0, 23, 80), "Do you wish to view active patient record flag details? Yes//") > 0 Then
.transmit "n"
.transmit Chr(13)
Pause (2.1)
End If
If InStr(Reflection.GetText(0, 0, 23, 80), "... press RETURN to continue ...") > 0 Then
.transmit Chr(13)
Pause (2#)
End If
If InStr(Reflection.GetText(0, 0, 23, 80), "Select Service/Specialty: ALL SERVICES//") > 0 Then
ElseIf InStr(Reflection.GetText(0, 0, 23, 80), "Select Patient:") > 0 Then
Dim WrongSSN As String
MsgBox "WTF"
' WrongSSN = InputBox("Please double check the SSN, it cannot be found in Vista")
If WrongSSN = vbNullString Then
On Error Resume Next
AddToConsults = False
Exit Function
Else
Forms!frmToChart.Form!SSN = WrongSSN
.transmit WrongSSN
.transmit Chr(13)
Pause (0.45)
End If
End If
'ADD MORE FLAGS HERE TO KEEP MOVING
End If
If InStr(strSQL, "...OK? Yes//") > 0 Then
.transmit Chr(13)
Pause (2#)
End If
If InStr(Reflection.GetText(0, 0, 23, 80), "Select Service/Specialty: ALL SERVICES//") > 0 Then
.transmit Forms!frmToChart.Form!ConsultTitle
.transmit Chr(13)
Pause (0.4)
Else
AddToConsults = False
MsgBox "Something Went Wrong"
Exit Function
End If
If InStr(Reflection.GetText(0, 0, 23, 80), "List From Starting Date: ALL DATES//") > 0 Then
.transmit Chr(13)
Pause (1.45)
End If
If InStr(Reflection.GetText(0, 0, 23, 80), "Select: Quit//") > 0 Then
'Call FindCorrectConsult
If FindCorrectConsult = False Then
MsgBox "There do not seem to be any consults for this Veteran with this information, or this consult is an old title."
AddToConsults = False
Exit Function
End If
End If
'******INSERT CONSULT GRAB HERE!!!
Select Case Forms!frmToChart.OptionCase
Case 1 'ADD COMMENT
.transmit "CM"
.transmit Chr(13)
.transmit Forms!frmToChart.Form!ConsultAddComment.Value
.transmit Chr(5)
.transmit "y"
.transmit Chr(13)
Pause (0.45)
Call AddSigners
Case 2 'RECEIVE
.transmit "RC"
.transmit Chr(13)
If InStr(Reflection.GetText(0, 0, 23, 80), "Who received it?:") > 0 Then
MsgBox RSSetName
.transmit RSSetName
.transmit Chr(13)
Pause (0.45)
If InStr(Reflection.GetText(0, 0, 23, 80), "Date/Time Actually Received NOW//") > 0 Then
.transmit Chr(13)
Pause (0.45)
.transmit Forms!frmToChart.Form!ConsultAddComment
.transmit Chr(5)
.transmit "y"
.transmit Chr(13)
Pause (0.45)
End If
Else
If InStr(Reflection.GetText(0, 0, 22, 80), "RC is not a valid selection.") > 0 Then
Else
If InStr(Reflection.GetText(0, 0, 22, 80), "This consult has already been Cancelled.") > 0 Then
MsgBox "This consult cannot be received."
Else
MsgBox "Something happened, I cannot finish the process."
End If
End If
End If
Case 3 'COMPLETE
.transmit "ct"
.transmit Chr(13)
'FindCorrectConsult
Pause (0.3)
If InStr(Reflection.GetText(0, 0, 23, 80), "Administratively complete this request?") > 0 Then
Pause (0.2)
.transmit "y"
.transmit Chr(13)
Pause (0.3)
Else
MsgBox "I ran into an error processing this, I don't think this consult can be completed, please try again."
.transmit "^"
.transmit Chr(13)
Exit Function
End If
If InStr(Reflection.GetText(0, 0, 23, 80), "Responsible Clinician:") > 0 Then
.transmit RSSetName
.transmit Chr(13)
Pause (0.45)
Else
MsgBox "I ran in to an error adding resposible party"
End If
If InStr(Reflection.GetText(0, 0, 23, 80), "Actual Date/Time of Activity:") > 0 Then
.transmit Chr(13)
Pause (0.2)
If InStr(Reflection.GetText(0, 0, 23, 80), "Are there significant findings? (Y/N/U):") > 0 Then
.transmit "U"
.transmit Chr(13)
Pause (0.5)
.transmit Forms!frmToChart.Form!ConsultAddComment
.transmit Chr(5)
.transmit "y"
.transmit Chr(13)
Pause (0.45)
End If
End If
Case 4 'DC
On Error GoTo DCERROR
Forms!frmToChart.AddAlert = True
.transmit "DC"
.transmit Chr(13)
Pause (0.3)
If InStr(Reflection.GetText(0, 0, 23, 80), "Responsible Clinician:") > 0 Then
.transmit RSSetName
.transmit Chr(13)
Pause (0.85)
Else
FindCorrectConsult
Pause (0.85)
.transmit RSSetName
.transmit Chr(13)
Pause (0.85)
'MsgBox "I ran in to an error adding resposible party"
'Exit Function
End If
If InStr(Reflection.GetText(0, 0, 23, 80), "Actual Date/Time of Activity:") > 0 Then
.transmit Chr(13)
Pause (0.5)
.transmit Forms!frmToChart.Form!ConsultAddComment
.transmit Chr(5)
.transmit "y"
.transmit Chr(13)
Pause (0.45)
Forms!frmToChart.AddAlert = True
.transmit "CM"
.transmit Chr(13)
.transmit "Please ensure authorization is cancelled"
.transmit Chr(5)
.transmit "y"
.transmit Chr(13)
Pause (0.45)
' Call AddSigners
Dim AlertName As String
Dim NameSelect As String
If InStr(Reflection.GetText(0, 0, 23, 80), "Additional alert recipients:") > 0 Then
If Forms!frmToChart.Form!AddAlert = True Then
AlertName = InputBox("Please enter a name for the alert. Format Lastname,FirstName")
If AlertName = "" Then
.transmit Chr(13)
Else
.transmit AlertName
.transmit Chr(13)
Pause (0.45)
End If
Do While Forms!frmToChart.Form!AddAlert = True
If InStr(Reflection.GetText(0, 0, 23, 80), "And Additional alert recipients:") > 0 Then
AlertName = InputBox("Please enter an additional name for the alert. Click OK if no additional alerts required!!!")
If AlertName = "" Then
.transmit Chr(13)
Forms!frmToChart.Form!AddAlert = False
Exit Do
Else
.transmit AlertName
.transmit Chr(13)
End If
ElseIf InStr(Reflection.GetText(0, 0, 23, 80), "CHOOSE") > 0 Then
NameSelect = InputBox("Please select which name you wish to add from Vista.")
If NameSelect = "" Then
MsgBox "You must select one"
Exit Function
Else
.transmit NameSelect
.transmit Chr(13)
End If
Else
Forms!frmToChart.Form!AddAlert = False
Exit Do
End If
Loop
End If
Else
.transmit Chr(13)
End If
'TEST ENDS HERE
Else
MsgBox "Something happened, I cannot finish the process."
Exit Function
End If
End Select
End With
Exit Function
DCERROR: MsgBox "DC ERROR"
Exit Function
Nosession: MsgBox "You need an active session of Vista open"
End Function