|
-
Sep 28th, 2006, 01:50 AM
#1
Thread Starter
Lively Member
Run time error no 9
I have a DataGrid name 'dgrIntems' and TextBox name 'txtsubcode' .
Datagrid shows the details when i enter the code in TextBox.otherwise datagrid is empty.
I write folowing code on dgrIntems_Click()
[vb code]
Private Sub dgrIntems_Click()
TxtPar.Text = dgrIntems.Columns(2).Text
TxtRate.Text = dgrIntems.Columns(5).Text
TxtPieces.Text = dgrIntems.Columns(6).Text
checkid = dgrIntems.Columns(0).Text
itemco = dgrIntems.Columns(1).Text
subitemcode = dgrIntems.Columns(3).Text
MonthVal = dgrIntems.Columns(15).Text
QuanV = dgrIntems.Columns(4).Text
End Sub
[/vb code]
If the DataGrid is empty and I click on DataGrid it shows an run time error '9'
i want to show the message in this condition.
how can i handel this error.
-
Sep 28th, 2006, 02:02 AM
#2
Re: Run time error no 9
what is the Err.Description you are getting...
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
Sep 28th, 2006, 02:12 AM
#3
Re: Run time error no 9
VB Code:
Private Sub dgrIntems_Click()
[B]If dgrIntems.Row = 1 Then Exit Sub
'Check If there is any data or not in the datagrid[/B]
TxtPar.Text = dgrIntems.Columns(2).Text
TxtRate.Text = dgrIntems.Columns(5).Text
TxtPieces.Text = dgrIntems.Columns(6).Text
checkid = dgrIntems.Columns(0).Text
itemco = dgrIntems.Columns(1).Text
subitemcode = dgrIntems.Columns(3).Text
MonthVal = dgrIntems.Columns(15).Text
QuanV = dgrIntems.Columns(4).Text
End Sub
-
Sep 28th, 2006, 05:31 AM
#4
Thread Starter
Lively Member
Re: Run time error no 9
 Originally Posted by shakti5385
VB Code:
Private Sub dgrIntems_Click()
[B]If dgrIntems.Row = 1 Then Exit Sub
'Check If there is any data or not in the datagrid[/B]
TxtPar.Text = dgrIntems.Columns(2).Text
TxtRate.Text = dgrIntems.Columns(5).Text
TxtPieces.Text = dgrIntems.Columns(6).Text
checkid = dgrIntems.Columns(0).Text
itemco = dgrIntems.Columns(1).Text
subitemcode = dgrIntems.Columns(3).Text
MonthVal = dgrIntems.Columns(15).Text
QuanV = dgrIntems.Columns(4).Text
End Sub
Sorry boss but the same error is repeatedly coming. The Error is Run time error '9' Subscript Out of range.
-
Sep 28th, 2006, 05:53 AM
#5
Re: Run time error no 9
use error handling something like this to display message
VB Code:
Private Sub dgrIntems_Click()
On Error GoTo errh
TxtPar.Text = dgrIntems.Columns(2).Text
TxtRate.Text = dgrIntems.Columns(5).Text
TxtPieces.Text = dgrIntems.Columns(6).Text
checkid = dgrIntems.Columns(0).Text
itemco = dgrIntems.Columns(1).Text
subitemcode = dgrIntems.Columns(3).Text
MonthVal = dgrIntems.Columns(15).Text
QuanV = dgrIntems.Columns(4).Text
Exit Sub
errh:
If Err.Number = 9 Then MsgBox "no data", vbCritical
End Sub
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Sep 28th, 2006, 05:55 AM
#6
Re: Run time error no 9
VB Code:
Exit Sub
errh:
If Err.Number = 9 Then MsgBox "no data", vbCritical
It is not the batter solution.. ......
@Koshiks
Can you tell in which line error is occuring..........
-
Sep 28th, 2006, 06:10 AM
#7
Re: Run time error no 9
It is not the batter solution.. ......
but it appears to be what he asks for in his original post
i want to show the message in this condition.
how can i handel this error.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Sep 28th, 2006, 06:16 AM
#8
Re: Run time error no 9
 Originally Posted by kaushiks
I have a DataGrid name 'dgrIntems' and TextBox
[vb code]
[/vb code]
You need to remove the space in between vb code to show the vbcode.
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
-
Sep 28th, 2006, 06:18 AM
#9
Re: Run time error no 9
 Originally Posted by westconn1
but it appears to be what he asks for in his original post
You have to check the condition that on which line error is occuring and what is the reason of this error..
Kosiks not specify the error line number... it is possible that error will be occuring through other reason..
Error handler is batter for showing the error... so we have to use according to the condition if there is no any solution then use the error handler....
-
Sep 28th, 2006, 06:20 AM
#10
Fanatic Member
Re: Run time error no 9
 Originally Posted by kaushiks
The Error is Run time error '9' Subscript Out of range.
one of the columns you are using doesn't exist.
check if each column-number exists. probably column 15 doesn't exist.
MonthVal = dgrIntems.Columns(15).Text
-
Sep 28th, 2006, 10:03 AM
#11
Re: Run time error no 9
 Originally Posted by robbedaya
one of the columns you are using doesn't exist.
Or there's no datga at all, so the row (there's an assumed row if one isn't specified) doesn't exist, so the row subscript (probably 0 in this case) is out of range, since UBound(Rows) is (effectively) -1.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Sep 28th, 2006, 10:15 AM
#12
Addicted Member
Re: Run time error no 9
If your getting your data from a Database you could use:
VB Code:
If Object.BOF or Object.EOF then
'No Data
Exit Sub
else
'Do grid work
End If
-
Sep 28th, 2006, 10:43 AM
#13
Re: Run time error no 9
The DataGrid.Row property will equal -1 if there is no selected row (either the grid is empty or the user is not clicking on a row).
Regardless, your code belongs in the RowColChange event, not the click event.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|