listview checkboxes checked

msmeth
12-15-2003, 07:37 AM
I have a listview with checkboxes that gets populated when the user clicks a button.

The user can then check certain records in the listview and click another button and more information for the selected recs are displayed (in another listview). Now, on the first click, the second listview is empty. So, I go back and do it again and then it works! This is how I'm doing it, but maybe there's a better way?


With ListView1
For i = 1 To .ListItems.Count
If .ListItems(i).Checked = True Then
ACCESSdb.Execute "INSERT INTO temp values ('" & ListView1.ListItems(i) & "')"
End If
Next
End With

For Each tb In ACCESSdb.TableDefs
If tb.Name = "ChosenEQTypes" Then
ACCESSdb.Execute "DROP TABLE ChosenEQTypes"
End If
Next
ACCESSdb.Execute "SELECT EqSummary.EQNUM, EqSummary.EQTYPE, EqSummary.DESCRIPTION AS Type INTO ChosenEQTypes FROM EqTypeSummary INNER JOIN (EqSummary INNER JOIN temp ON EqSummary.EQTYPE = temp.EQTYPE) ON EqTypeSummary.EQTYPE = EqSummary.EQTYPE"

setListView2 'this sets up the datasource and column sizing, etc...

Shurik12
12-15-2003, 07:46 AM
Hi,

So after you click that button the code you've provided is executed.
How do you populate the second ListView?

Regards,
Shurik.

msmeth
12-15-2003, 07:52 AM
Hi,

So after you click that button the code you've provided is executed.
How do you populate the second ListView?

Regards,
Shurik.

Yes the code is executed. The first time though, nothing shows up in the second LVW, but then I hit 'BACK' and check it again and then it works.

This is how I populate the 2nd listview....it's in the function setListView2


With rsFleetDetails
.ActiveConnection = cn
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockOptimistic
.Open "SELECT * FROM ChosenEQTypes"
End With

Do While Not rsFleetDetails.EOF
Set lvnode = ListView2.ListItems.Add(, , rsFleetDetails!Description)

lvnode.SubItems(1) = "" & rsFleetDetails!NUM
lvnode.SubItems(2) = "" & rsFleetDetails!Regular
lvnode.SubItems(3) = "" & rsFleetDetails![Total Hours]

rsFleetDetails.MoveNext
Loop

rsFleetDetails.Close

Shurik12
12-15-2003, 07:56 AM
Looks like ACCESSdb.Execute .... not finished doing what it's supposed to before you trying populate the ListView...
Could you try to add DoEvents just after ACCESSdb.Execute to see if it helps?

Shurik.

msmeth
12-15-2003, 08:10 AM
Hey. Nope, no go....I even have a sleep function in there and still nothing.

msmeth
12-15-2003, 08:21 AM
Well, I found this interesting. I put a break point in the setListView2 function right after the statement to open the recordset.....the program didn't stop! Apparently it never got to that line and thus never opened the recordset! When I step through it though, it gets there! Wow...I am so completely baffled :huh:

Shurik12
12-15-2003, 08:22 AM
OK, for any reasons, could you check whehter the recordset rsFleetDetails is effectively populated "from the first time"?
( if the recordset is fetched, did you try to suspend the execution after .Open "SELECT * FROM ChosenEQTypes")

Shurik12
12-15-2003, 08:23 AM
>I put a break point in the setListView2 function right after the statement to open the recordset

Seems like you have On Error Resume Next somewhere in the code?

msmeth
12-15-2003, 08:25 AM
OK, for any reasons, could you check whehter the recordset rsFleetDetails is effectively populated "from the first time"?
( if the recordset is fetched, did you try to suspend the execution after .Open "SELECT * FROM ChosenEQTypes")

I guess my last post answered both of those? :)

I put a break point at the begin of the With block and that's fine the first time.

I put a break point at the End With line (so right after .Open "Select....") and it never gets there on the first time!

The second time through, it gets there and the records are correct.

Shurik12
12-15-2003, 08:29 AM
> I guess my last post answered both of those?

I read your last post after I sent mine, so...


Again, since you never get to the brek point after .Open it might mean
that it errors but since you have (do you?) On Error Resume Next it
doesn't debug.

msmeth
12-15-2003, 08:36 AM
> I guess my last post answered both of those?

I read your last post after I sent mine, so...


Again, since you never get to the brek point after .Open it might mean
that it errors but since you have (do you?) On Error Resume Next it
doesn't debug.

Well, yes and no. Initially I had this:


For Each tb In ACCESSdb.TableDefs
If tb.Name = "ChosenEQTypes" Then
ACCESSdb.Execute "DROP TABLE ChosenEQTypes"
End If
Next


But, the make table query after that isn't working once I get into the setListView2 function! Upon the .Open call, it says the table doesn't exist!

So, I put in the version with On Error Resume Next, but turned it off after I drop the table. Same error as above.

Then I just left it as On Error Resume Next, which apparently has it's own problem you're telling me :huh:

It seems to me this make table query isn't executing properly the first time thru....

msmeth
12-15-2003, 08:39 AM
This is really annoying me! If I check the database when the program tells me the table doesn't exist, it's lying! The table is very much there in the database and populated with the correct values!

Shurik12
12-15-2003, 08:46 AM
Just thought why instead of using

ACCESSdb.Execute "DROP TABLE ChosenEQTypes"

you could try

ACCESSdb.Execute "DELETE * FROM ChosenEQTypes"

See if it works.

msmeth
12-15-2003, 09:02 AM
Just thought why instead of using

ACCESSdb.Execute "DROP TABLE ChosenEQTypes"

you could try

ACCESSdb.Execute "DELETE * FROM ChosenEQTypes"

See if it works.

The reason is because I'm making a new tbl and, in Access, the table has to be deleted (if it exists) first so I had to simulate that in VB...

msmeth
12-15-2003, 09:15 AM
Well, it seems to be working now. I deleted the table at the beginning of the function instead of right before the select-into statement. Guess it needs time or something? :confused:

Thanks for your help Shruik.

Shurik12
12-15-2003, 09:22 AM
>Guess it needs time or something?

Seems to be so.


Cheers,
Shurik.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum