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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid increment selbookmarks 1

Status
Not open for further replies.

AMHCLH

Programmer
Nov 26, 2002
23
0
0
US
I have a datagrid and want to allow the user to select multiple records. The program will then use the contract numbers of these selected records to build a query to be passed to a report printing only those selected contracts. This is the code I am using to create the query, but it never increments to the next bookmark. It continues to add the same contract number to the query over and over. How do you increment through the selbookmarks?

Dim sQry As String
Dim sFirst As Boolean
Dim varBmk As Variant

sFirst = True
For Each varBmk In DataGrid1.SelBookmarks
If sFirst Then
sQry = ("{JOBCOST.Contn} = '" & DataGrid1.Columns(0) & "'")
sFirst = False
Else
sQry = sQry & " or {JOBCOST.Contn} = '" & DataGrid1.Columns(0) & "'"
End If
DataGrid1.SelBookmarks.Remove (0)
Next

 
That (removing an element of the collection) is not a wise thing to do in a For/Each.

Better would be to do this:

Do While DataGrid1.SelBookmarks.Count <> 0
'Your code to do your thingy here

If DBGrid1.SelBookmarks.Count > 0 Then DataGrid1.SelBookmarks.Remove 0
Loop
 
CCLINT,

Thanks for the response. I changed the code and now it loops through the correct number of times, but the value DataGrid1.Columns(0) doesn't change for each record. It is always the value of the first contract selected. Any ideas?
 
Because you are not looping through records, but bookmarks...

Set DataGrid1.Bookmark = SelBookmark (0)
 
My code now looks like this:

Do While DataGrid1.SelBookmarks.Count <> 0
Set DataGrid1.Bookmark = DataGrid1.SelBookmarks(0)
If sFirst Then
sQry = (&quot;{JOBCOST.Contn} = '&quot; & DataGrid1.Columns(0) & &quot;'&quot;)
sFirst = False
Else
sQry = sQry & &quot; or {JOBCOST.Contn} = '&quot; & DataGrid1.Columns(0) & &quot;'&quot;
End If

If DataGrid1.SelBookmarks.Count > 0 Then DataGrid1.SelBookmarks.Remove 0
Loop


BUT I get an error on the &quot;Set Datagrid1.Bookmark = DataGrid1.SelBookmarks(0)&quot; command. Error 424 &quot;Object required.&quot;
 
Yes, I'm sorry...remove the SET

DataGrid1.Bookmark = SelBookmark (0)
 
CClint,

Thank you! It works perfectly! You get a star!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top