Maybe if you post the code, one can analyse where the problem lies.
Sukesh
Quote:> I am converting a vb5 rdo application to a vb6 ado application. I had to
> drop my db grid and use the data grid and the ado control.
> I'm doing a phone book type application. When the program opens the text
> boxes at the top and the data grid at the botton are populated with the
> entire recordset. I have a text box that allows them to put a name in to
> search.
> I have the opening where both the text boxes and the grid are filled
> working. I put in one name to search and it finds it and both my text
boxes
> and my grid are filled. The problem is when I put in the second name to
> search. The text boxes are filled but the grid is empty., It makes no
> sense to me why it works once and not twice. My search routine is a
divide
> and conquer type of search. I cannot identify where I loose the
population
> in the grid. I'm wondering if it is the way I have the grid and the
control
> attached to each other. Any help will be greatly appreciated.
> Jean
Private Sub txtSrch_KeyPress(KeyAscii As Integer)
'SQL = "Execute Update_phone '" & RTrim$(txtName) & "', '" &
RTrim$(txtPhone) & "', '" & strUserName & "'"
'On Error GoTo err_ProcS
'If KeyAscii = 39 Then KeyAscii = 96
'If KeyAscii = 39 Then KeyAscii = 39
'KeyAscii = 39
If KeyAscii = 13 Then
KeyAscii = 0
strname = txtSrch.Text
If strname = "" Then
Exit Sub
End If
Dim maxval As Single
Dim minval As Single
Dim newmin As Variant
Dim newmax As Single
Dim boldoit As Boolean
'rstPhone.Requery
rstPhone.Close
rstPhone.CursorLocation = adUseClient
rstPhone.CursorType = adOpenDynamic
rstPhone.LockType = adLockOptimistic
rstPhone.Open
rstPhone.MoveLast
maxval = rstPhone.AbsolutePosition
minval = 0
boldoit = True
Trim (rstPhone("fo_name"))
MsgBox ("I'm refreshiunf")
dgPhone.Refresh
Do While boldoit = True
If UCase(rstPhone("fo_name")) = UCase(strname) Then
Exit Do
End If
newmin = minval + Int((maxval - minval) / 2)
'rstPhone.Bookmark = newmin
'rstPhone.Move
rstPhone.AbsolutePosition = newmin
If UCase(rstPhone("fo_name")) = UCase(strname) Then
Exit Do
End If
If UCase(rstPhone("fo_name")) > UCase(strname) Then
newmax = maxval - Int((maxval - minval) / 2)
'rstPhone.AbsolutePosition = newmax
'rstPhone.Bookmark = newmax
If UCase(rstPhone("fo_name")) = UCase(strname) Then
Exit Do
End If
maxval = newmax
Else
minval = newmin
End If
If maxval - 1 = minval Then
'Call DisplayRecord
MsgBox ("I'm here")
Set AdcPhone.Recordset = rstPhone ' JC Modified
'AdcPhone.Refresh
Exit Do
End If
Loop
If rstPhone("fo_name") = strname Then
' Call DisplayRecord
txtSrch.Text = ""
txtSrch.SetFocus
Else
' rstPhone.MoveNext
Call DisplayRecord
'rstPhone.AbsolutePosition = maxval
txtSrch.Text = ""
txtSrch.SetFocus
txtSrch.TabStop = True
End If
' 'DBGrid1.SelLength = 100
''DBGrid1.SetFocus
End If
End Sub
> Maybe if you post the code, one can analyse where the problem lies.
> Sukesh
> > I am converting a vb5 rdo application to a vb6 ado application. I had
to
> > drop my db grid and use the data grid and the ado control.
> > I'm doing a phone book type application. When the program opens the
text
> > boxes at the top and the data grid at the botton are populated with the
> > entire recordset. I have a text box that allows them to put a name in to
> > search.
> > I have the opening where both the text boxes and the grid are filled
> > working. I put in one name to search and it finds it and both my text
> boxes
> > and my grid are filled. The problem is when I put in the second name to
> > search. The text boxes are filled but the grid is empty., It makes no
> > sense to me why it works once and not twice. My search routine is a
> divide
> > and conquer type of search. I cannot identify where I loose the
> population
> > in the grid. I'm wondering if it is the way I have the grid and the
> control
> > attached to each other. Any help will be greatly appreciated.
> > Jean
It would appear that you're doing a lot of work emulating the Find function
in the recordset; all you have to do is open the recordset, and call Find
as in the following code example:
'BeginFindVB
'To integrate this code
'replace the data source and initial catalog values
'in the connection string
Public Sub FindX()
' connection and recordset variables
Dim Cnxn As New ADODB.Connection
Dim rstTitles As New ADODB.Recordset
Dim strCnxn As String
Dim strSQLTitles As String
' record variables
Dim mark As Variant
Dim count As Integer
' open connection
Set Cnxn = New ADODB.Connection
strCnxn = "Provider=sqloledb;Data Source=MyServer;Initial
Catalog=Pubs;User Id=sa;Password=; "
Cnxn.Open strCnxn
' open recordset with default parameters which are
' sufficient to search forward through a Recordset
Set rstTitles = New ADODB.Recordset
strSQLTitles = "SELECT title_id FROM titles"
rstTitles.Open strSQLTitles, Cnxn, adOpenStatic, adLockReadOnly,
adCmdText
count = 0
rstTitles.Find "title_id LIKE 'BU%'"
Do While Not rstTitles.EOF
'continue if last find succeeded
Debug.Print "Title ID: "; rstTitles!title_id
'count the last title found
count = count + 1
' note current position
mark = rstTitles.Bookmark
rstTitles.Find "title_id LIKE 'BU%'", 1, adSearchForward, mark
' above code skips current record to avoid finding the same row
repeatedly;
' last arg (bookmark) is redundant because Find searches from
current position
Loop
Debug.Print "The number of business titles is " & count
' clean up
rstTitles.Close
Cnxn.Close
Set rstTitles = Nothing
Set Cnxn = Nothing
End Sub
'EndFindVB
Hope this helps!
Steven Bras, MCSD
Microsoft Developer Support/Visual Basic WebData
This posting is provided "AS IS" with no warranties, and confers no rights.
Are you secure? For information about the Microsoft Strategic Technology
Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.
Yes, your code is bit hard to follow. I suggest you use SQL to get the
desired data, instead of Find function.
The snippet of the code would be as follows.
1. The user types in the search word in the text box (say txtSearchBox)
2. SQL = "SELECT whatever FROM Table WHERE SomeField='"& txtSearchBox.Text &
"'"
Then with Search button click event
3. ObjRecordset.Open SQL,ObjConnection
4. Set DataGrid.DataSource=ObjRecordset
This is presuming you are using ADO Library.
If you are using ADO control then the click event would be as follows
strSQL = "SELECT whatever FROM Table WHERE SomeField='" &
txtSearchBox.Text & "'"
Adodc1.RecordSource = strSQL 'You have to use RecordSource and not
Recordset
Adodc1.Refresh ' This is important
Set DataGrid.DataSource = Adodc1
This way there will be less overheads on the client (less code &
processing), as this would fetch only the desired records.
And moreover, no need to worry about find, movefirst, movelast,
absolutepositions, bookmarks, and what-have-you, etc.
Of course, sooner or later, you will have to switch over to using ADO
Library instead of ADO control, which gives one a greater control on the
application.
Sukesh
> Private Sub txtSrch_KeyPress(KeyAscii As Integer)
> 'SQL = "Execute Update_phone '" & RTrim$(txtName) & "', '" &
> RTrim$(txtPhone) & "', '" & strUserName & "'"
> 'On Error GoTo err_ProcS
> 'If KeyAscii = 39 Then KeyAscii = 96
> 'If KeyAscii = 39 Then KeyAscii = 39
> 'KeyAscii = 39
> If KeyAscii = 13 Then
> KeyAscii = 0
> strname = txtSrch.Text
> If strname = "" Then
> Exit Sub
> End If
> Dim maxval As Single
> Dim minval As Single
> Dim newmin As Variant
> Dim newmax As Single
> Dim boldoit As Boolean
> 'rstPhone.Requery
> rstPhone.Close
> rstPhone.CursorLocation = adUseClient
> rstPhone.CursorType = adOpenDynamic
> rstPhone.LockType = adLockOptimistic
> rstPhone.Open
> rstPhone.MoveLast
> maxval = rstPhone.AbsolutePosition
> minval = 0
> boldoit = True
> Trim (rstPhone("fo_name"))
> MsgBox ("I'm refreshiunf")
> dgPhone.Refresh
> Do While boldoit = True
> If UCase(rstPhone("fo_name")) = UCase(strname) Then
> Exit Do
> End If
> newmin = minval + Int((maxval - minval) / 2)
> 'rstPhone.Bookmark = newmin
> 'rstPhone.Move
> rstPhone.AbsolutePosition = newmin
> If UCase(rstPhone("fo_name")) = UCase(strname) Then
> Exit Do
> End If
> If UCase(rstPhone("fo_name")) > UCase(strname) Then
> newmax = maxval - Int((maxval - minval) / 2)
> 'rstPhone.AbsolutePosition = newmax
> 'rstPhone.Bookmark = newmax
> If UCase(rstPhone("fo_name")) = UCase(strname) Then
> Exit Do
> End If
> maxval = newmax
> Else
> minval = newmin
> End If
> If maxval - 1 = minval Then
> 'Call DisplayRecord
> MsgBox ("I'm here")
> Set AdcPhone.Recordset = rstPhone ' JC Modified
> 'AdcPhone.Refresh
> Exit Do
> End If
> Loop
> If rstPhone("fo_name") = strname Then
> ' Call DisplayRecord
> txtSrch.Text = ""
> txtSrch.SetFocus
> Else
> ' rstPhone.MoveNext
> Call DisplayRecord
> 'rstPhone.AbsolutePosition = maxval
> txtSrch.Text = ""
> txtSrch.SetFocus
> txtSrch.TabStop = True
> End If
> ' 'DBGrid1.SelLength = 100
> ''DBGrid1.SetFocus
> End If
> End Sub
> > Jean
> > Maybe if you post the code, one can analyse where the problem lies.
> > Sukesh
> > > I am converting a vb5 rdo application to a vb6 ado application. I had
> to
> > > drop my db grid and use the data grid and the ado control.
> > > I'm doing a phone book type application. When the program opens the
> text
> > > boxes at the top and the data grid at the botton are populated with
the
> > > entire recordset. I have a text box that allows them to put a name in
to
> > > search.
> > > I have the opening where both the text boxes and the grid are filled
> > > working. I put in one name to search and it finds it and both my text
> > boxes
> > > and my grid are filled. The problem is when I put in the second name
to
> > > search. The text boxes are filled but the grid is empty., It makes
no
> > > sense to me why it works once and not twice. My search routine is a
> > divide
> > > and conquer type of search. I cannot identify where I loose the
> > population
> > > in the grid. I'm wondering if it is the way I have the grid and the
> > control
> > > attached to each other. Any help will be greatly appreciated.
> > > Jean
1. which grid to use: DBGrid, data grid, MSFlexgrid
Hello everybody
As there are so many grids in VB6 such as Data Bound Grid Control, Data Grid
Control and MSFlexGrid Contrl, which grid should I use ?
thanks
pc
3. GRID: How to prevent moving in grid?
4. Need Oracle banking applications
5. Pasting a column of numbers in Excel into a grid/db grid in VB
7. Copying selected row from a grid to antother grid
8. SNMP API for OEM and Oracle MIB
9. DB Grid to DB Grid Question!
11. True DB Grid 5.0 - Sort a grid
12. flex grid or data grid or neither?
13. how to gracefully remove a grid column (in middle of grid)