Results 1 to 13 of 13

Thread: Run time error no 9

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2005
    Posts
    76

    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.

  2. #2
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    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.


  3. #3
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: Run time error no 9

    VB Code:
    1. Private Sub dgrIntems_Click()
    2. [B]If dgrIntems.Row = 1 Then Exit Sub
    3. 'Check If there is any data or not in the datagrid[/B]
    4. TxtPar.Text = dgrIntems.Columns(2).Text
    5. TxtRate.Text = dgrIntems.Columns(5).Text
    6. TxtPieces.Text = dgrIntems.Columns(6).Text
    7. checkid = dgrIntems.Columns(0).Text
    8. itemco = dgrIntems.Columns(1).Text
    9. subitemcode = dgrIntems.Columns(3).Text
    10. MonthVal = dgrIntems.Columns(15).Text
    11. QuanV = dgrIntems.Columns(4).Text
    12. End Sub

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2005
    Posts
    76

    Re: Run time error no 9

    Quote Originally Posted by shakti5385
    VB Code:
    1. Private Sub dgrIntems_Click()
    2. [B]If dgrIntems.Row = 1 Then Exit Sub
    3. 'Check If there is any data or not in the datagrid[/B]
    4. TxtPar.Text = dgrIntems.Columns(2).Text
    5. TxtRate.Text = dgrIntems.Columns(5).Text
    6. TxtPieces.Text = dgrIntems.Columns(6).Text
    7. checkid = dgrIntems.Columns(0).Text
    8. itemco = dgrIntems.Columns(1).Text
    9. subitemcode = dgrIntems.Columns(3).Text
    10. MonthVal = dgrIntems.Columns(15).Text
    11. QuanV = dgrIntems.Columns(4).Text
    12. End Sub

    Sorry boss but the same error is repeatedly coming. The Error is Run time error '9' Subscript Out of range.

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Run time error no 9

    use error handling something like this to display message

    VB Code:
    1. Private Sub dgrIntems_Click()
    2. On Error GoTo errh
    3. TxtPar.Text = dgrIntems.Columns(2).Text
    4. TxtRate.Text = dgrIntems.Columns(5).Text
    5. TxtPieces.Text = dgrIntems.Columns(6).Text
    6. checkid = dgrIntems.Columns(0).Text
    7. itemco = dgrIntems.Columns(1).Text
    8. subitemcode = dgrIntems.Columns(3).Text
    9. MonthVal = dgrIntems.Columns(15).Text
    10. QuanV = dgrIntems.Columns(4).Text
    11.  
    12. Exit Sub
    13. errh:
    14. If Err.Number = 9 Then MsgBox "no data", vbCritical
    15. 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

  6. #6
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: Run time error no 9

    VB Code:
    1. Exit Sub
    2. errh:
    3. 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..........

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  8. #8
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: Run time error no 9

    Quote 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.

  9. #9
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Thumbs up Re: Run time error no 9

    Quote 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....

  10. #10
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872

    Re: Run time error no 9

    Quote 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

  11. #11
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Run time error no 9

    Quote 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

  12. #12
    Addicted Member
    Join Date
    Apr 2006
    Posts
    174

    Re: Run time error no 9

    If your getting your data from a Database you could use:

    VB Code:
    1. If Object.BOF or Object.EOF then
    2.    'No Data
    3.    Exit Sub
    4. else
    5.    'Do grid work
    6. End If

  13. #13
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    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
  •  



Click Here to Expand Forum to Full Width