Here is my code that allows user to search for records by Name and Date...records found are displayed in the Grid.....if user enters nothing then it prompts use to enter something....i guess the queston is....How do i let the user know there is no current record found or if that they must enter the EXACT name and Date to find the record?
Also, i get an error "subscript out of range" when no record is selected and the "total" buttons are clicked....it works fine when records are found.
Here is what i have....
Private Sub Command26_Click()
Dim db As Database
Dim rs As Recordset
Dim strFile As String
Dim strSQL As String
strFile = "a:\tracker"
a = InputBox("Enter Agent Name", "Search"
b = InputBox("Enter Date as MM-DD-YY", "Search"
strSQL = "SELECT * FROM tracker where aname = '" & a & "' and date = '" & b & "'"
If a = "" And b = "" Then
MsgBox "You must enter a valid Agent Name and Date.", , "Search "
Else
Set db = OpenDatabase(strFile)
Set rs = db.OpenRecordset(strSQL)
Call DisplayRSGrid(rs, MSFlexGrid1)
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
End If
End Sub
Private Function TotalColumn(grid As MSFlexGrid, ByVal ColIndex As Long) As Long
Dim R As Integer
Dim total As Integer
For R = 0 To grid.Rows - 1
If IsNumeric(grid.TextMatrix(R, ColIndex)) Then
total = total + (grid.TextMatrix(R, ColIndex))
End If
Next R
TotalColumn = total
End Function
Private Sub Command22_Click()
Text1.Text = TotalColumn(MSFlexGrid1, 12)
End Sub
Also, i get an error "subscript out of range" when no record is selected and the "total" buttons are clicked....it works fine when records are found.
Here is what i have....
Private Sub Command26_Click()
Dim db As Database
Dim rs As Recordset
Dim strFile As String
Dim strSQL As String
strFile = "a:\tracker"
a = InputBox("Enter Agent Name", "Search"
b = InputBox("Enter Date as MM-DD-YY", "Search"
strSQL = "SELECT * FROM tracker where aname = '" & a & "' and date = '" & b & "'"
If a = "" And b = "" Then
MsgBox "You must enter a valid Agent Name and Date.", , "Search "
Else
Set db = OpenDatabase(strFile)
Set rs = db.OpenRecordset(strSQL)
Call DisplayRSGrid(rs, MSFlexGrid1)
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
End If
End Sub
Private Function TotalColumn(grid As MSFlexGrid, ByVal ColIndex As Long) As Long
Dim R As Integer
Dim total As Integer
For R = 0 To grid.Rows - 1
If IsNumeric(grid.TextMatrix(R, ColIndex)) Then
total = total + (grid.TextMatrix(R, ColIndex))
End If
Next R
TotalColumn = total
End Function
Private Sub Command22_Click()
Text1.Text = TotalColumn(MSFlexGrid1, 12)
End Sub