Private Sub cmdNextRec_Click()
Const Formclose As Long = 3021
On Error GoTo ErrorMsg
'set ADO connection
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSelect As String, msgbtn As Integer, msgbtn2 As Integer
Set con = New ADODB.Connection
con.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=C:\My Documents\SalesTracking.mdb"
con.Open
Set rs = New Recordset
'Setup query to pull only records that have not been looked at by a sales rep and
'...called back
strSelect = "SELECT * FROM Main WHERE CallBackShift = '" & txtSalesShift.Text & "' AND AgentCmpltd <>'""'"
rs.Open strSelect, MyDataEnvironment.MyConnection, adOpenKeyset, adLockOptimistic
'we need to check and make sure that the user complete's the appropriate fields
'...before continuing!
If txtSaleRep.Text = "" Then
MsgBox "Please check the box to use the form before continuing!", vbCritical, "Your Name?"
chkCB.SetFocus
Exit Sub
Else
If lstAppGen.Text = "" Then
MsgBox "Please select if an application was generated!", vbCritical, "Application Generated?"
lstAppGen.SetFocus
Exit Sub
Else
'At the end of the recordset alert the user and close the connection
If rs.EOF Then
msgbtn = MsgBox("There are currently no Call Back records!", vbInformation, "No Records")
GoTo CleanUp
'otherwise move to the next record within the select query and update the
'...appropriate fields
Else
rs.MoveNext
chkCB.Value = 0
rs("AgentCmpltd") = txtSaleRep.Text
rs("CmpltdDate") = txtDateCmpltd.Text
rs("AppGen") = lstAppGen.Text
txtSlsRefNot.Text = rs.RecordCount
txtSlsRefNot.Text = rs.RecordCount - 1
End If
End If
'Ask the user if they want to quit the program since there are no more records
If msgbtn = vbOK Then
msgbtn2 = MsgBox("Would you like to quit the program now?", vbInformation + vbYesNo, "Quit?")
If msgbtn2 = vbYes Then
rs.Close
End
Else
'do nothing
End If
End If
End If
'To avoid the error '3021
DisplayEnd:
Exit Sub
ErrorMsg:
If Err = Formclose Then
frmMsgboxLstRec.Show
End If
Resume DisplayEnd
'close connections
CleanUp:
rs.Close
con.Close
Set rs = Nothing
Set con = Nothing
End Sub
____________________________________________________
Private Sub Form_Activate()
Dim msgbtn As Integer, strSelect As String
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
'open the ADO connection to the Access database
Set con = New ADODB.Connection
con.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=C:\My Documents\SalesTracking.mdb"
con.Open
Set rs = New Recordset
'set up the SELECT query to pull only customers who have not been called back
strSelect = "SELECT * FROM Main WHERE CallBackShift = '" & txtSalesShift.Text & "' AND AgentCmpltd <>'""'"
rs.Open strSelect, MyDataEnvironment.MyConnection, adOpenKeyset, adLockOptimistic
'check to see if there are records in the query, if not then move to the first
'record and fills the textboxes with the fields in the query
If rs.RecordCount = 0 Then
msgbtn = MsgBox("There are currently no Call Back records!", vbInformation, "No Records")
Else
rs.MoveFirst
txtDateRef.Text = rs("DateRef")
txtCstmrFName.Text = rs("CustomerFName")
txtCstmrLName.Text = rs("CustomerLName")
txtSSNum.Text = rs("SS")
txtHSBCAcct.Text = rs("ExsistAcct")
'The following If statements are to avoid a "Invalid Null" error message
'since these fields may or may not have data in them
If txtBrochOnly.Text = "" Or Null Then
'do nothing
Else
txtBrochOnly.Text = rs("BrochOnly")
End If
If txtBrochAddress.Text = "" Or Null Then
'do nothing
Else
txtBrochAddress.Text = rs("BrochAddress")
End If
txtCBPref.Text = rs("CallbackDate")
txtBestTime.Text = rs("BestTime")
txtCBShift.Text = rs("CallBackShift")
txtPriPhn.Text = rs("PrimaryPhone")
If txtCallBackCmmnts.Text = "" Or Null Then
'do nothing
Else
txtCallBackCmmnts.Text = rs("CallbackComments")
End If
If txtSecPhn.Text = "" Or Null Then
'do nothing
Else
txtSecPhn.Text = rs("SecPhone")
End If
If txtChecking.Text = "" Or Null Then
'do nothing
Else
txtChecking.Text = rs("CHECKING")
End If
If txtSavings.Text = "" Or Null Then
'do nothing
Else
txtSavings.Text = rs("SAVINGS")
End If
If txtCredit.Text = "" Or Null Then
'do nothing
Else
txtCredit.Text = rs("CREDIT CARD")
End If
If txtATM.Text = "" Or Null Then
'DO NOTHING
Else
txtATM.Text = rs("ATM/MASTERMONEY")
End If
If txtSelect.Text = "" Or Null Then
'DO NOTHING
Else
txtSelect.Text = rs("SELECT CREDIT")
End If
If txtInsurance.Text = "" Or Null Then
'DO NOTHING
Else
txtInsurance.Text = rs("INSURANCE")
End If
If txtInvestments.Text = "" Or Null Then
'DO NOTHING
Else
txtInvestments.Text = rs("INVESTMENTS")
End If
If txtCD.Text = "" Or Null Then
'DO NOTHING
Else
txtCD.Text = rs("CD")
End If
If txtHomeEquity.Text = "" Or Null Then
'DO NOTHING
Else
txtHomeEquity.Text = rs("HOME EQUITY")
End If
If txtInstallment.Text = "" Or Null Then
'DO NOTHING
Else
txtInstallment.Text = rs("INSTALLMENT")
End If
If txtTuition.Text = "" Or Null Then
'DO NOTHING
Else
txtTuition.Text = rs("TUITION PLUS LOC")
End If
If txtOther.Text = "" Or Null Then
'DO NOTHING
Else
txtOther.Text = rs("OTHER")
End If
If txtFinalCmmnts.Text = "" Or Null Then
'DO NOTHING
Else
txtFinalCmmnts.Text = rs("FinalComments")
End If
'show the total number of records in the query
txtSlsRefNot.Text = rs.RecordCount
End If
'when there are no more records then close the form, and close connections
If msgbtn = vbOK Then
Unload Me
End If
rs.Close
con.Close
Set rs = Nothing
Set con = Nothing
End Sub