Hello e/one,
im getting error no. 9 "subscript out of range" in following situation.
- i have a data grid on page on which i place a query to select data from SQL SERVER 2000 database just like that "select size_number, product_size, type_number from product_size"
-Below this grid i have 2 textboxes and 1 combobox.
-Now i want to show same data appear in data grid at the same time, user clicks on any row of datagrid. the user clicks in datagrid, the data of same row will be shown below in textboxes and combo.(type_number is in combo)
-Now its working successfully if i places only 2 things (i.e. text boxes)
when i add third item (combobox) it produces error...
-Can anyone HELP me...........its urgent...im showing some code here...
####Code Starts######
Option Explicit
Dim clscombo As New clsfillcombo
Private Sub cmdclose_Click()
Unload frmsize
Unload frmcategory
Unload frmproduct
Unload frmsupplier
frmwelcome.Show
End Sub
Private Sub cmddelete_Click()
On Error GoTo error_Delete
Dim rs As ADODB.Recordset
Dim sSql As String
Dim strtypenumber As String
If MsgBox("Are you sure you want to delete the selected record?", vbQuestion + vbYesNo + vbDefaultButton2, "TR") = vbYes Then
sSql = "Delete from product_size where size_number= '" & dgsize.Columns(0).Text & "'"
cn.Execute sSql
Set rs = Nothing
MDIForm1.Adodc1.Refresh
dgsize.Refresh
End If
Exit Sub
error_Delete:
If Err.Number = -2147217900 Then
MsgBox "This Size is in used, It cannot be deleted.", vbExclamation, "TR"
End If
End Sub
Private Sub cmdedit_Click()
txtnumber.Enabled = True
txtname.Enabled = True
cbotype.Enabled = True
cmdupdate.Visible = True
End Sub
Private Sub cmdnew_Click()
frmnewsize.Show
End Sub
Private Sub cmdupdate_Click()
'On Error GoTo error_update
With MDIForm1.Adodc1
.Recordset.Fields("size_number").Value = frmsize.txtnumber
.Recordset.Fields("product_size").Value = frmsize.txtname
.Recordset.Fields("type_number").Value = frmsize.cbotype
.Recordset.Update
MsgBox "Record has been Updated Successfully", vbInformation, "TR"
txtnumber.Enabled = False
txtname.Enabled = False
cbotype.Enabled = False
cmdupdate.Visible = False
End With
setDataGrid
'error_update:
'MsgBox Err.Description, vbInformation, "TR"
End Sub
Private Sub dgsize_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
setDataGrid
End Sub
Private Sub Form_Load()
On Error GoTo load_error
clscombo.fillProductType cbotype, cn
With MDIForm1.Adodc1
.RecordSource = "select * from product_size"
.Refresh
Set dgsize.DataSource = MDIForm1.Adodc1
dgsize.Refresh
End With
setDataGrid
txtnumber.Enabled = False
txtname.Enabled = False
cbotype.Enabled = False
cmdupdate.Visible = False
load_error:
If Err.Number = 6160 Then
MsgBox Err.Description, vbInformation, "TR"
cmdedit.Enabled = False
cmddelete.Enabled = False
End If
End Sub
Private Function setDataGrid()
With dgsize
txtnumber.Text = .Columns(1).Text '######working here
txtname.Text = .Columns(2).Text '######working here
cbotype.Text = .Columns(3).Text '######Now producing ERROR 9 here after adding this 1 line code
End With
End Function
Private Function invalidupdate() As Boolean
If Trim(txtnumber.Text) = "" Then
MsgBox "Size Number is invalid", vbInformation, "T.R. TRADERS"
invalidupdate = True
txtnumber.SetFocus
Exit Function
ElseIf Trim(txtname.Text) = "" Then
MsgBox "Product Size is invalid", vbInformation, "T.R. TRADERS"
invalidupdate = True
txtname.SetFocus
Exit Function
End If
End Function
Private Sub Form_Unload(Cancel As Integer)
Set clscombo = Nothing
End Sub
####Code Ends#######