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, 11:49 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

How many records are there in that list box? Try changing:

Dim intCurrentRow As Integer

To:

Dim intCurrentRow As Long

mmcdonal

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

Thanks a lot
After changing to Long am able to filter and update table. But the Serial no is not getting removed from the listbox.If it cannot be removed anyother option of preventing the same serial no getting printed second time?

Basically i want to avoid duplicate print of that serial No.
 
Old December 21st, 2007, 12:26 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

In order to remove the Serial No from the list box, you need to go to Design view and open the properties dialog box for the list. Then select the data tab. Then select the query designer. Then make sure that the Print Field is in the query, and that you put No in the criteria so that the list box only displays records where Print = No. Close the designer and click Yes to save the changes.
Then go to the Format Tab and make the the column count reflects the new column, and set the column widths so that the last column (Print) has a width of 0".

Make sure to do an Update Query when the form opens to set all the print column values to No.


mmcdonal

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

Thanks a lot for your help,it is working fine.

Will come back if i have any doubts...
Again thanks a lot for your time.
 
Old December 21st, 2007, 01:24 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Whew. Well that is good. I had it working on my version of the data structure. Just little typos and overlooked variables. That must be a huge list in that list box to overflow a PK variable.

See, there is a lesson I forgot since I work with smaller datasets. When taking an Autonumber field into a variable, always use Long since Integer is likely to overflow - especially with SQL Server. Yikes.

mmcdonal

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

Iam Now removing the serial no from listbox after printing.But i have same serial no for more than one city, so when i select serial no from [lstsrl] with one city from [lstsl], the other city with same serial no is also getting updated in table.Can it be resolved by adding city also so that if the serial no and city is selected that particular record should be updated.
 
Old December 26th, 2007, 10:31 AM
Authorized User
 
Join Date: Dec 2007
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Can you help on this....

Iam Now removing the serial no from listbox after printing.But i have same serial no for more than one city, so when i select serial no from [lstsrl] with one city from [lstsl], the other city with same serial no is also getting updated in table.Can it be resolved by adding city also so that if the serial no and city is selected that particular record should be updated.
 
Old December 27th, 2007, 12:32 AM
Authorized User
 
Join Date: Dec 2007
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?
---------
I have same serial no for more than one city, so even i choose one city with serial no the other city is also getting updated, can you tell me how to make table update only when the serial no and city is selected.Is it possible.Can you help on this please...
 
Old December 27th, 2007, 08:09 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

It seems you only want one list box then, with both the city and serial no.

Create a local table with the proper columns (cityID, City, Serial No, Print, I think) and then when the form opens, delete all the data in the table with a delete query, then populate the table with an append query that pulls in all the combinations of cities and serial numbers (simple Select Distinct etc).

Then take your parameters from that one list box.

The alternative is to create a cascading list box, and then have the user select a city first, and then based on the city they select, show them the remaining serial numbers that are associated with that city.

mmcdonal

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

Can you please explain how to code for cascading listbox...





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.