Hi,
Im doing a search on an Access table and the following code works in retrieving records that exist in the table however it throws up an error when the record is not found. Has anyone got any idea how to overcome this, it would bemuch appreciated
Thanks
Private Sub CmdSearch_Click()
MSFlexGrid1.FormatString = " <|PC ID |<PC Vendor |<PC Make/Model |<Memory |<Operating System |<Location |< Business Dept ID"
Dim adoconnection As ADODB.Connection
Set adoconnection = New ADODB.Connection
adoconnection.Open ("Provider=Microsoft.jet.oledb.4.0;" & "Data Source =H:\AssetTracking.mdb"
MSFlexGrid1.Visible = True
Set rs = New ADODB.Recordset
rs.Open "select * from PC where PCMakeModel ='" & TxtMakeModel.Text & "' and BusinessDeptID ='" & TxtBU.Text & "'", adoconnection, adOpenDynamic, adLockOptimistic
Dim irow As Integer
With MSFlexGrid1
Rows = 1 'counter used to assign the row number
rs.MoveFirst
While Not rs.EOF
Rows = Rows + 1
rs.MoveNext
Wend
.Rows = Rows
.Cols = 8
irow = 1 'counter used to assign the row number
rs.MoveFirst
Do Until rs.EOF
.TextMatrix(irow, 1) = rs!PCID
.TextMatrix(irow, 2) = rs!PCVendor
.TextMatrix(irow, 3) = rs!PCMakeModel
.TextMatrix(irow, 4) = rs!Memory
.TextMatrix(irow, 5) = rs!OperatingSystem
.TextMatrix(irow, 6) = rs!Location
.TextMatrix(irow, 7) = rs!BusinessDeptID
rs.MoveNext
irow = irow + 1
Loop
rs.Close
Set rs = Nothing
End With
End Sub
Im doing a search on an Access table and the following code works in retrieving records that exist in the table however it throws up an error when the record is not found. Has anyone got any idea how to overcome this, it would bemuch appreciated
Thanks
Private Sub CmdSearch_Click()
MSFlexGrid1.FormatString = " <|PC ID |<PC Vendor |<PC Make/Model |<Memory |<Operating System |<Location |< Business Dept ID"
Dim adoconnection As ADODB.Connection
Set adoconnection = New ADODB.Connection
adoconnection.Open ("Provider=Microsoft.jet.oledb.4.0;" & "Data Source =H:\AssetTracking.mdb"
MSFlexGrid1.Visible = True
Set rs = New ADODB.Recordset
rs.Open "select * from PC where PCMakeModel ='" & TxtMakeModel.Text & "' and BusinessDeptID ='" & TxtBU.Text & "'", adoconnection, adOpenDynamic, adLockOptimistic
Dim irow As Integer
With MSFlexGrid1
Rows = 1 'counter used to assign the row number
rs.MoveFirst
While Not rs.EOF
Rows = Rows + 1
rs.MoveNext
Wend
.Rows = Rows
.Cols = 8
irow = 1 'counter used to assign the row number
rs.MoveFirst
Do Until rs.EOF
.TextMatrix(irow, 1) = rs!PCID
.TextMatrix(irow, 2) = rs!PCVendor
.TextMatrix(irow, 3) = rs!PCMakeModel
.TextMatrix(irow, 4) = rs!Memory
.TextMatrix(irow, 5) = rs!OperatingSystem
.TextMatrix(irow, 6) = rs!Location
.TextMatrix(irow, 7) = rs!BusinessDeptID
rs.MoveNext
irow = irow + 1
Loop
rs.Close
Set rs = Nothing
End With
End Sub