Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create msgbox

Status
Not open for further replies.

homesick

Programmer
Dec 5, 2001
55
CA
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





 
For your first issue, you want to test the record count of 'rs' before you issue this line:

Call DisplayRSGrid(rs, MSFlexGrid1)

You do that like this:

If rs.bof and re.eof then MsgBox "No records found with that name and date, plese try again"

=======================================

>>"subscript out of range"
Test grid.Rows before you loop.
If you do not have records this number is 0.
This this line of code:
For R = 0 To grid.Rows - 1
becomes:
For R = 0 To 0 - 1
OR
For R = 0 To - 1

... you can not loop from 0 to -1 :)

 
The first issue is solved.....THANKS... as for the second issue....it works but now it won't sum....basically....i have 4 textboxes that grabs totals from a Grid with 4 corresponding buttons....my last button sums all the totals into a grand total into a label...it works with my previous code but it stays as "0" with the code you suggested......any advice?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top