Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 21st, 2007, 10:22 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

What line is the error on?

mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old December 21st, 2007, 10:25 AM
Authorized User
 
Join Date: Dec 2007
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Gives error on the below line:

If lstprdt.ItemsSelected.Count > 0 Then
 
Old December 21st, 2007, 10:25 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Also, what tables are each list box based on?

mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old December 21st, 2007, 10:27 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

That is your fault. That should be:

If lstsrl.ItemsSelected.Count > 0 Then

mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old December 21st, 2007, 10:30 AM
Authorized User
 
Join Date: Dec 2007
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think i have made one mistake.
In listbox1 the record source is from table(say a sepearte table for City)-Master_city
In Listbox2 the record source is from main table(where the update happens) - Master

May be this leads to an error?Sorry i just now checked it..
 
Old December 21st, 2007, 10:34 AM
Authorized User
 
Join Date: Dec 2007
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You have given following code sayig for text. But lstsrl i have Autonumber field....

'For Text
Set ctrl = Me.lstsrl
For intCurrentRow = 0 To ctrl.ListCount - 1
    If ctrl.Selected(intCurrentRow) Then
        lRecord = ctrl.Column(0, intCurrentRow)
        sSQL = "UPDATE product SET [Print] = Yes WHERE [Serial No] = " & lRecord
        Set rs = New ADODB.Recordset
        rs.Open sSQL, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
    End If
Next intCurrentRow
 
Old December 21st, 2007, 10:47 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Your post stated Serial No was integer, and City was text, so I did it this way.
Also, if the recordset can't find a field with the name indicated, then it will throw a missing object error. So if it is looking for a field from another table, it will throw this error.
 Please post the tables, their fields, and the fields taken in each list box.


mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old December 21st, 2007, 11:11 AM
Authorized User
 
Join Date: Dec 2007
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Listbox1 = lstsl, City (TEXT) - ROW SOURCE IS FROM MASTER_CITY TABLE
Listbox2 = lstsrl, Serial No (AUTONUMBER) - ROW SOURCE IS FROM PRODUCT TABLE(the main table)
Reportname = Product1
Tablename = Product
The flag to be updated is "PRINT" fieldname in "PRODUCT Table".

PRODUCT is the main table where all fields are.


Have i given the info what you asked for ?
 
Old December 21st, 2007, 11:31 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I modded the code to remove products from the lstsrl list, but not cities from the lstsl list:

Dim varItem As Variant
Dim strwhere As String
Dim strreport As String
Dim rs As ADODB.Recordset
Dim sSQL As String
Dim lRecord As Long
Dim sRecord As String
Dim ctrl As Control
Dim intCurrentRow As Integer

strwhere = ""
strreport = "Product1"

'Using Text as Column(0)
If lstsl.ItemsSelected.Count > 0 Then
    strwhere = strwhere & "("
        For Each varItem In lstsl.ItemsSelected
            strwhere = strwhere & "[city] = '" _
            & Me![lstsl].Column(0, varItem) & "' Or "
        Next varItem
        strwhere = Left(strwhere, Len(strwhere) - 4)
          strwhere = strwhere & ")"
End If

If Len(strwhere) > 0 Then strwhere = strwhere & " And "

'Using integer PK as Column(0)
If lstsrl.ItemsSelected.Count > 0 Then
    strwhere = strwhere & "("
        For Each varItem In lstsrl.ItemsSelected
            strwhere = strwhere & "[Serial No] =" & Me![lstsrl].Column(0, varItem) & " Or "
        Next varItem
        strwhere = Left(strwhere, Len(strwhere) - 4)
          strwhere = strwhere & ")"
End If

If Len(strwhere) > 0 Then strwhere = strwhere

'For Text
Set ctrl = Me.lstsrl
For intCurrentRow = 0 To ctrl.ListCount - 1
    If ctrl.Selected(intCurrentRow) Then
        lRecord = ctrl.Column(0, intCurrentRow)
        sSQL = "UPDATE Product SET [Print] = Yes WHERE [Serial No] = " & lRecord
        Set rs = New ADODB.Recordset
        rs.Open sSQL, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
    End If
Next intCurrentRow
intCurrentRow = 0

Me.lstsrl.Requery



The resulting WHERE clause produced when I selected the City I created called "Columbia" and the third product in the list (Serial No 2) was:

strwhere = ([city] = 'Columbia') AND ([Serial No] = 2)

This could be expressed without all the () like:

[city] = 'Columbia' AND [Serial No] = 2

Anyway, this worked for me and removed the products from the list. Not the cities. Did you also want cities removed?


mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old December 21st, 2007, 11:46 AM
Authorized User
 
Join Date: Dec 2007
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

But i still get error saying

Run-time error '6':

Overflow

in the line:
For intCurrentRow = 0 To ctrl.ListCount - 1

"Anyway, this worked for me and removed the products from the list. Not the cities. Did you also want cities removed?"

I dont understand what you are saying - removed the products from the list.
I Want the Serial No to be cleared from the listbox, not the Cities.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Listbox problem when insert or update hcanales ASP.NET 1.x and 2.0 Application Design 1 September 21st, 2006 02:53 PM
How to Update a Listbox on Different Form boxwalah C# 2 February 24th, 2006 12:22 PM
loop through listbox and update record stoneman Access 1 August 5th, 2005 03:43 AM
How to pass parameters from a multiselect listbox Jeff1218 Classic ASP Databases 3 February 14th, 2005 03:39 PM
listBox +Update problem dvarrin C# 0 November 26th, 2003 05:25 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.