I have a simple application that is retrieving a recordset from a database and populating a flexgrid with the record set accordingly. The idea is that the user will enter an field "txtItemCode" and hit ENTER, then the record will appear at the bottom of the form in the FlexGrid. Then the focus will return back to txtItemCode and the user can enter another item that will populate more rows into the FlexGrid. Every time I enter an Item however the following code dumps to the error handler?
Private Sub cmdEnter_Click()
On Error GoTo errhandler
Dim strsql As String
Dim inti As Integer
Dim blnflag As Boolean
If txtItemCode.Text = "" Then
MsgBox "Item code cannot be empty, Please Enter Item Code", vbCritical
txtItemCode.SetFocus
Exit Sub
End If
strsql = " select a.sku_num, a.itm_cd, b.vsn, a.size_cd, a.color_des, c.upc_cd" & _
" from gm_sku a, gm_itm b, gm_sku2upc_cd c" & _
" where a.sku_num = c.sku_num" & _
" and a.itm_cd = b.itm_cd" & _
" and b.itm_cd = '" & txtItemCode.Text & "'"
Set rsmain = New ADODB.Recordset
rsmain.Open strsql, cn, adOpenKeyset, adLockReadOnly
If rsmain.EOF Then
MsgBox "UPC data data does not exist for this Item Code, Pleas re-enter", vbCritical
txtItemCode.SetFocus
Exit Sub
Else
blnflag = False
For inti = 1 To MSFItem.Rows - 1
If Left(MSFItem.TextMatrix(inti, 0), 9) = txtItemCode.Text Then
blnflag = True
Exit For
End If
Next
If blnflag = False Then
Do While Not rsmain.EOF()
If MSFItem.TextMatrix(1, 0) = "" Then
inti = 1
Else
inti = MSFItem.Rows
MSFItem.Rows = MSFItem.Rows + 1
End If
MSFItem.TextMatrix(inti, 0) = rsmain("a.sku_num")
MSFItem.TextMatrix(inti, 1) = rsmain("a.itm_cd")
MSFItem.TextMatrix(inti, 2) = rsmain("a.vsn")
MSFItem.TextMatrix(inti, 3) = rsmain("a.size_cd")
MSFItem.TextMatrix(inti, 4) = rsmain("a.color_des")
MSFItem.TextMatrix(inti, 5) = rsmain("c.upc_cd")
rsmain.MoveNext
Loop
Else
MsgBox " This Item is already entered", vbInformation
End If
txtItemCode.Text = ""
txtItemCode.SetFocus
Exit Sub
End If
Exit Sub
errhandler:
MsgBox "Errors occured while retreiving the item information" & vbCrLf & "Please Click on Reset Button and Redo the process" & vbCrLf & Err.Number & ":" & Err.Description, vbCritical
Exit Sub
End Sub
Private Sub cmdEnter_Click()
On Error GoTo errhandler
Dim strsql As String
Dim inti As Integer
Dim blnflag As Boolean
If txtItemCode.Text = "" Then
MsgBox "Item code cannot be empty, Please Enter Item Code", vbCritical
txtItemCode.SetFocus
Exit Sub
End If
strsql = " select a.sku_num, a.itm_cd, b.vsn, a.size_cd, a.color_des, c.upc_cd" & _
" from gm_sku a, gm_itm b, gm_sku2upc_cd c" & _
" where a.sku_num = c.sku_num" & _
" and a.itm_cd = b.itm_cd" & _
" and b.itm_cd = '" & txtItemCode.Text & "'"
Set rsmain = New ADODB.Recordset
rsmain.Open strsql, cn, adOpenKeyset, adLockReadOnly
If rsmain.EOF Then
MsgBox "UPC data data does not exist for this Item Code, Pleas re-enter", vbCritical
txtItemCode.SetFocus
Exit Sub
Else
blnflag = False
For inti = 1 To MSFItem.Rows - 1
If Left(MSFItem.TextMatrix(inti, 0), 9) = txtItemCode.Text Then
blnflag = True
Exit For
End If
Next
If blnflag = False Then
Do While Not rsmain.EOF()
If MSFItem.TextMatrix(1, 0) = "" Then
inti = 1
Else
inti = MSFItem.Rows
MSFItem.Rows = MSFItem.Rows + 1
End If
MSFItem.TextMatrix(inti, 0) = rsmain("a.sku_num")
MSFItem.TextMatrix(inti, 1) = rsmain("a.itm_cd")
MSFItem.TextMatrix(inti, 2) = rsmain("a.vsn")
MSFItem.TextMatrix(inti, 3) = rsmain("a.size_cd")
MSFItem.TextMatrix(inti, 4) = rsmain("a.color_des")
MSFItem.TextMatrix(inti, 5) = rsmain("c.upc_cd")
rsmain.MoveNext
Loop
Else
MsgBox " This Item is already entered", vbInformation
End If
txtItemCode.Text = ""
txtItemCode.SetFocus
Exit Sub
End If
Exit Sub
errhandler:
MsgBox "Errors occured while retreiving the item information" & vbCrLf & "Please Click on Reset Button and Redo the process" & vbCrLf & Err.Number & ":" & Err.Description, vbCritical
Exit Sub
End Sub