Contents:

Select Full Patient Medications List

 

Transfer User-Selected Medications from ListBox1 to ListBox2

 

Make Paragraph Using Selected Medications

 

Print Medications List

 

Print Prescriptions

 

 

Chapter 11: VBA Coding- Prescription Writer

      The prescription printing method using VBA involves several steps:

  1. Select the patient's medications from a back-end Access table, then populate ListBox1.

  2. The end user selects what medications are needed to work with in that particular instance. You then have to select out those medications and add them into ListBox2.

  3. Activity 1► Make a paragraph with the selected medications.

  4. Activity 2► Print out a list of medications.

  5. Activity 3► You have to use a method to scoop out 4 medications at a time, then send them as a group to a prescriptions template.

Select Full Patient Medications List

 

            This is performed when after the end user selects a patient.

 

:

 

Here is the associated code that selects this patient's medications:

 

' fill the needed variables

ptn = frmSOAP.PTNAME3
acctno = frmSOAP.ACCT
' fill in the medications listbox
Set rs = db.OpenRecordset("SELECT MEDICATIONS.MD1, MEDICATIONS.X FROM MEDICATIONS WHERE MEDICATIONS.[ACCT] = " & frmSOAP.ACCT & " ORDER BY Medications.md1;")
With rs
If .RecordCount = 0 Then
Exit Sub
End If
.MoveLast
NoOfRecords = .RecordCount
.MoveFirst
' Set the number of Columns = number of Fields in recordset
ListBox1.ColumnCount = .Fields.Count
' Load the ListBox with the retrieved records
ListBox1.Column = .GetRows(NoOfRecords)
' Cleanup
.Close
db.Close
End With
'tt = "0 in"
uu = "1.3 in"
vv = "0 in"
aa = "1.3 in"
ListBox1.ColumnWidths = uu & ";" & vv
ListBox1.ListWidth = aa

 

Transfer User-Selected Medications from ListBox1 to ListBox2

 

            The way the modern-day WordEMRProject works, as soon as the patient is selected on page 1 of the SOAP form, everything is automated, including all the steps from this point on, but medications can be removed and resent back to ListBox2 ("Print Meds List").

 

 

            Here is the underlying code either when the patient is selected or you press the "Add" ClickButton:

 

Private Sub CommandButton15_Click()
If conDebug Then On Error GoTo Proc_Error
If ListBox1.ListIndex = -1 Then
Else
Msg = "."
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
Msg = ListBox1.List(i)
ListBox2.AddItem Msg
DoCmd.RunSQL "INSERT INTO MedicationsTemp SELECT Medications.* FROM Medications WHERE MEDICATIONS.MD1 = " & Chr(34) & Msg & Chr(34) & " and MEDICATIONS.[ACCT] = " & frmSOAP.ACCT & ";"
End If
Next i
End If
Exit Sub
Proc_Exit:
Exit Sub
Proc_Error:
Call EMRError("WORD EMR Project.dot/" & Me.Name & ": CommandButton11_Click()", Err.Number, Err.Source, Err.Description)
Resume Proc_Exit
End Sub

 

            Notice that we've introduced a new variable, the Msg., which represents each medication selected as the For... Next loop is activated.

 

            Now when the process is automated using the patient select combobox, this is the code that is run:

 

'check all meds listed
For i = 0 To ListBox1.ListCount - 1
ListBox1.Selected(i) = True
Next
'check to see if any meds listed, then transfer them
If ListBox1.ListIndex = -1 Then
Else
Msg = "."
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
Msg = ListBox1.List(i)
ListBox2.AddItem Msg
End If
Next i

 

Make Paragraph Using Selected Medications

           

            This is automatically invoked when a patient is chosen by the following call-up:

 

Call CommandButton7_Click

 

This is the actual code that is run:

 

Call CommandButton7_Click
'check all meds listed
For i = 0 To ListBox1.ListCount - 1
ListBox1.Selected(i) = True
Next
'check to see if any meds listed, then transfer them
If ListBox1.ListIndex = -1 Then
Else
Msg = "."
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
Msg = ListBox1.List(i)
ListBox2.AddItem Msg
End If
Next i
End If

' here is the code to full-in the textbox with medications paragraph
DoCmd.RunSQL "INSERT INTO MedicationsTemp SELECT Medications.* FROM Medications WHERE MEDICATIONS.[ACCT] = " & frmSOAP.ACCT & ";"
Call MedCalculate_Click
Call PEDefaults_Click
Proc_Exit:
Exit Sub
Proc_Error:
Call EMRError("WORD EMR Project.dot/" & Me.Name & ": frmSOAP.[PTNAME3]AME_Click()", Err.Number, Err.Source, Err.Description)
Resume Proc_Exit
End Sub

 

            Here is the code for the MedCalculate_Click method that fills in the textbox for the prescriptions paragraph:

 

Sub MedCalculate_Click()
Set db = OpenDatabase(conDBpath2)
SQLStmt = "SELECT MEDICATIONS.* FROM MEDICATIONS WHERE Medications.[ACCT]= " & frmSOAP.ACCT & ";" '
Set rs = db.OpenRecordset(SQLStmt, dbOpenSnapshot)
vv = ""
yy = ""
On Error Resume Next
With rs
If .RecordCount = 0 Then
GoTo Proc_Error
Else
.MoveLast
.MoveFirst
While Not .EOF
yy = Trim(![MD1]) & ", " & Trim(![Sig])
vv = vv & "; " & yy
.MoveNext
Wend
End If
Trim (vv)
If Left(vv, 2) = "; " Then
vv = Right(vv, Len(vv) - 2)
End If
vv = vv & "."
End With
Me!Medications3 = vv
yy = " "
vv = " "
db.Close
rs.Close
Exit_Command169_Click:
Exit Sub
Proc_Error:
MsgBox "There are no medications for this patient."
Me.Medications3 = " "
Exit Sub
Err_Command169_Click:
MsgBox Err.Description
Resume Exit_Command169_Click
End Sub

 

Print Medications List

 

(to be completed this week)

 

Print Prescriptions

 

(to be completed this week)