Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search functionality, need to populate FlexGrid

Status
Not open for further replies.

rundmc

Programmer
Jan 16, 2003
15
US
Hi,
Im trying to do a search on a table called PC on the basis of two field values being inputted to two text boxes: Txtdept and TxtMakeModel. I am using a FlexGrid but the code I have isnt loading the values into the FlexGrid. Can anyone find whats wrong with the code Im using...

Thanks

Private Sub Command1_Click()
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
Dim RS As ADODB.Recordset
Set RS = New ADODB.Recordset




RS.Open "select * from PC where PCMakeModel ='" & TxtMakeModel.Text & "' and BusinessDeptID ='" & Txtdept.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

While Not 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
Wend
RS.Close

Set RS = Nothing

End With
End Sub
 
You don't seem to be moving through the recordset or incrementing irow.

.TextMatrix(irow, 7) = RS!BusinessDeptID
RS.MoveNext
irow = irow + 1

Wend

Nowadays most people prefer the structure:
Do While Not RS.EOF
...
...
Loop
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Rundmc

did you try

MSFLEXGRID1.Datasource = RS

This binds it to your recordset and will allow it to populate.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top