Re: vb datagrid.row
From: Mark J. McGinty (mmcginty_at_spamfromyou.com)
Date: 08/22/04
- Previous message: JFS: "Runtime error 3706"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 22 Aug 2004 14:06:58 -0700
The row property references a position in the visible display area of the
grid.
What you need to do instead of this is:
Clone the recordset that's bound to the datagrid
Call the Find method on the clone
If the row is found, set the grid.Bookmark property to the recordset
clone's Bookmark property
Dim rsClone As ADODB.Recordset
Set rsClone = GetGridRecordset(grid)
rsClone.MoveFirst
rsClone.Find "company_name = '" & c_control & "'"
If not rsClone.EOF Then grid.Bookmark = rsClone.Bookmark
Public Function GetGridRecordset(ByRef Grid AS DataGrid) As ADODB.Recordset
Set GetGridRecordset = Nothing
If Grid Is Nothing Then Exit Function
Dim rs As ADODB.Recordset
Dim obj As Object
Set obj = Grid.DataSource
If (Grid.DataMember <> Empty) Then
Set rs = obj.DataSource
Else
Set rs = obj
End If
If (TypeOf rs Is ADODB.Recordset) Then
Set GetGridRecordset = rs
Else
Debug.Print "GetGridRecordset", "No recordset for grid ", Grid.Name
End If
Set rs = Nothing
Set obj = Nothing
End Function
-Mark
"ugurceng" <ugur113@hotmail.com> wrote in message
news:urttqNmNEHA.556@TK2MSFTNGP10.phx.gbl...
> hello
> I have a datagrid and I transfer the data to datagrid from database. And
> then i want to find a record that is taken from text and show it in the
> datagrid. So I used the "row" property of datagrid1
> but there is poblem with this property. The error occurs "Run Time error
> 6148 - Invalid Row number"
> Can anyone help me?
> Do you suggest to use another property?
>
>
> Private Sub CMDFindCompany_Click()
> Dim conn As Connection
> Dim rs As Recordset
> Dim c_name As String
> Dim c_control As String
> Dim i As Integer
> Set conn = New Connection
> Set rs = New Recordset
> conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & App.Path &
> "\siparis.mdb "
> rs.Open "select * from table_company_name ", conn, adOpenStatic,
> adLockOptimistic
>
> rs.MoveFirst
> c_control = LCase(Text1)
>
> Do Until rs.EOF
> c_name = LCase(Trim(rs.Fields("company_name")))
>
> If (c_name = c_control) Then
>
> FORM_Add_Company.DataGrid1.Row = i
>
> rs.MoveLast
> rs.MoveNext
> Me.Hide
>
> Else
> rs.MoveNext
> i = i + 1
> If c_name <> c_control And rs.EOF Then
> MsgBox c_control & " there is no company with this name..."
> Me.Hide
> End If
> End If
>
>
- Previous message: JFS: "Runtime error 3706"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|