Public Function Authorize(iStudentID As Integer) As Boolean
' this method will determine if the student can
' purchase a book at this price.
' the student's account balance must stay under $500
Dim rsAccountBalance As ADODB.Recordset
Dim dBalance As Double
Dim dPotentialBalance As Double
Dim strWarning As String
' create the recordset object
Set rsAccountBalance = New ADODB.Recordset
' open the recordset using the argument for the Student ID
rsAccountBalance.Open "Select AccountBalance from Students where StudentID = " & Str(iStudentID), cnStateUBookstore, adOpenStatic, adLockReadOnly
' get the account information from the record returned
dBalance = rsAccountBalance!AccountBalance
' add the value of the book to the balance
dPotentialBalance = dBalance + mvarPrice
' determine if the student can afford to buy the book
Select Case dPotentialBalance
Case Is < 450
Authorize = True
Case Is <= 499
Authorize = True
strWarning = "After this transaction, you will owe the University $" & Str(dPotentialBalance)
' raise the event that this book purchase will put them within $50 of the limit ($500)...
RaiseEvent Warning(strWarning)
Case Is >= 500
Authorize = False
strWarning = "Over the Limit! You currently owe the University $" & Str(dBalance) & " and are not authorized to buy this book."
' raise the event
RaiseEvent Warning(strWarning)
Case Else
Authorize = False
End Select
' close and clean up the recordset
rsAccountBalance.Close
Set rsAccountBalance = Nothing
End Function