19299 Order items in list box
Sign Up |  Live StatsLive Stats    Articles 37,305| Comments 176,998| Members 19,397, Newest birinder| Online 398
Home Contact
 (Forgotten?): 
    Sikhism
    For best SPN experience, use Firefox Internet Browser!


                                                                   Your Banner Here!    




Order items in list box

Our Donation Goal : Why Donate? : Donate Today! : Donate Anonymously (ਗੁਪਤ) : Our Family of Supporters
Goal this month: 500 USD, Received: 100 USD (20%)
Please Donate...
     
Related Topics...
Thread Thread Starter Forum Replies Last Post
Reorder (ABC) items in a list box Jennifer Cali Information Technology 4 28-Jul-2006 08:34 AM
Access 2000 order form line items not adding to total peter.haik@gmail.com Information Technology 2 28-Jul-2006 08:25 AM
dynamically change the order of items in a combo box jacchops Information Technology 2 28-Jul-2006 08:24 AM
Sending values from one list box to another list box in Access millie.patel@gmail.com Information Technology 7 28-Jul-2006 08:18 AM
List of items what control to use and how to store them? pokdbz Information Technology 2 11-Nov-2005 20:09 PM


Tags
order, items, list, box
Reply Post New Topic In This Forum Stay Connected to Sikhism, Click Here to Register Now!
  #1 (permalink)  
Old 28-Jul-2006, 08:17 AM
millie.patel@gmail.com's Avatar millie.patel@gmail.com
Guest
 
Posts: n/a
   
   
Order items in list box

  Donate Today!   Email to Friend  Tell a Friend   Show Printable Version  Print   Contact sikhphilosophy.net Administraion for any Suggestions, Ideas, Feedback.  Feedback  

Register to Remove Advertisements
hi all --
I have a combobox (name cboProgram);
Once the program is loaded, a listbox of associated Elements are
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/information-technology/10974-order-items-in-list-box.html
generated.

The listbox (name lboElement), which has ElementID, ElementName,
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=10974
ElementOrder

When the items appear in the list box, I have the "UP" "DOWN" arrows to
the left of it to allow the user to change the ElementOrder.

How can this be done?

Thanks!


*







Do share your immediate thoughts or reactions on this issue? We value your views! Login Now! or Sign Up Today! to share your views with us.. Gurfateh!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 28-Jul-2006, 08:17 AM
Dirk Goldgar's Avatar Dirk Goldgar
Guest
 
Posts: n/a
   
   
Re: Order items in list box

wrote in message
news:1149690155.363042.295480@y43g2000cwc.googlegr oups.com
> hi all --
> I have a combobox (name cboProgram);
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=10974
> Once the program is loaded, a listbox of associated Elements are
> generated.
>
> The listbox (name lboElement), which has ElementID, ElementName,
> ElementOrder
>
> When the items appear in the list box, I have the "UP" "DOWN" arrows
> to the left of it to allow the user to change the ElementOrder.
>
> How can this be done?


Where do the list items come from? If it's a table, and the table
contains the fields ElementID, ElementName, and ElementOrder, then the
process of moving an element up or down is going to involve swapping the
values of ElementOrder in two records -- probably via update queries--
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=10974
and then requerying the list box.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


Reply With Quote
  #3 (permalink)  
Old 28-Jul-2006, 08:17 AM
millie.patel@gmail.com's Avatar millie.patel@gmail.com
Guest
 
Posts: n/a
   
   
Re: Order items in list box

The list items come from
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=10974
tblElements
ElementID
ElementName
ElementOrder

Dirk Goldgar wrote:
> wrote in message
> news:1149690155.363042.295480@y43g2000cwc.googlegr oups.com
> > hi all --
> > I have a combobox (name cboProgram);
> > Once the program is loaded, a listbox of associated Elements are
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=10974
> > generated.
> >
> > The listbox (name lboElement), which has ElementID, ElementName,
> > ElementOrder
> >
> > When the items appear in the list box, I have the "UP" "DOWN" arrows
> > to the left of it to allow the user to change the ElementOrder.
> >
> > How can this be done?

>
> Where do the list items come from? If it's a table, and the table
> contains the fields ElementID, ElementName, and ElementOrder, then the
> process of moving an element up or down is going to involve swapping the
> values of ElementOrder in two records -- probably via update queries--
> and then requerying the list box.
>
> --
> Dirk Goldgar, MS Access MVP
> www.datagnostics.com
>
> (please reply to the newsgroup)


Reply With Quote
  #4 (permalink)  
Old 28-Jul-2006, 08:17 AM
Dirk Goldgar's Avatar Dirk Goldgar
Guest
 
Posts: n/a
   
   
Re: Order items in list box

wrote in message
news:1149692178.103309.101990@g10g2000cwb.googlegr oups.com
> The list items come from
> tblElements
> ElementID
> ElementName
> ElementOrder
>
> Dirk Goldgar wrote:
>> wrote in message
>> news:1149690155.363042.295480@y43g2000cwc.googlegr oups.com
>>> hi all --
>>> I have a combobox (name cboProgram);
>>> Once the program is loaded, a listbox of associated Elements are
>>> generated.
>>>
>>> The listbox (name lboElement), which has ElementID, ElementName,
>>> ElementOrder
>>>
>>> When the items appear in the list box, I have the "UP" "DOWN" arrows
>>> to the left of it to allow the user to change the ElementOrder.
>>>
>>> How can this be done?

>>
>> Where do the list items come from? If it's a table, and the table
>> contains the fields ElementID, ElementName, and ElementOrder, then
>> the process of moving an element up or down is going to involve
>> swapping the values of ElementOrder in two records -- probably via
>> update queries-- and then requerying the list box.


I hadn't written an example of this before, so I took a moment now to do
it. Set your list box's RowSource property to this:

SELECT ElementID, ElementName, ElementOrder
FROM tblElements
ORDER BY tblElements.ElementOrder;

Name your "Up" and "Down" buttons "cmdMoveUp" and "cmdMoveDown",
respectively.

Now add the following event procedures to your form's class module:

'----- start of code -----
Private Sub cmdMoveDown_Click()

On Error GoTo Err_Handler

Dim lngCurrItem As Long
Dim lngCurrOrder As Long
Dim lngCurrRow As Long
Dim lngNextItem As Long
Dim lngNextOrder As Long
Dim lngNextRow As Long

Dim ws As DAO.Workspace
Dim db As DAO.Database

Dim fInTrans As Boolean

With Me.lboElement

If IsNull(.Value) Then
DoCmd.Beep
Exit Sub
End If

lngCurrRow = .ItemsSelected(0)
If lngCurrRow = (.ListCount - 1) Then
DoCmd.Beep
Exit Sub
End If

lngCurrItem = .Value
lngCurrOrder = .Column(2)

lngNextRow = lngCurrRow + 1
lngNextItem = .ItemData(lngNextRow)
lngNextOrder = .Column(2, lngNextRow)

Set ws = DBEngine.Workspaces(0)
Set db = ws.Databases(0)

ws.BeginTrans
fInTrans = True

db.Execute _
"UPDATE tblElements SET ElementOrder = " & lngNextOrder & _
" WHERE ElementID = " & lngCurrItem, _
dbFailOnError

db.Execute _
"UPDATE tblElements SET ElementOrder = " & lngCurrOrder & _
" WHERE ElementID = " & lngNextItem, _
dbFailOnError

ws.CommitTrans

.Requery

End With

Exit_Point:
On Error Resume Next
If fInTrans Then
ws.Rollback
End If
Set db = Nothing
Set ws = Nothing
Exit Sub

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_Point

End Sub

Private Sub cmdMoveUp_Click()

On Error GoTo Err_Handler

Dim lngCurrItem As Long
Dim lngCurrOrder As Long
Dim lngCurrRow As Long
Dim lngPrevItem As Long
Dim lngPrevOrder As Long
Dim lngPrevRow As Long

Dim ws As DAO.Workspace
Dim db As DAO.Database
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=10974

Dim fInTrans As Boolean

With Me.lboElement

If IsNull(.Value) Then
DoCmd.Beep
Exit Sub
End If

lngCurrRow = .ItemsSelected(0)
If lngCurrRow = 0 Then
DoCmd.Beep
Exit Sub
End If

lngCurrItem = .Value
lngCurrOrder = .Column(2)

lngPrevRow = lngCurrRow - 1
lngPrevItem = .ItemData(lngPrevRow)
lngPrevOrder = .Column(2, lngPrevRow)

Set ws = DBEngine.Workspaces(0)
Set db = ws.Databases(0)

ws.BeginTrans
fInTrans = True

db.Execute _
"UPDATE tblElements SET ElementOrder = " & lngPrevOrder & _
" WHERE ElementID = " & lngCurrItem, _
dbFailOnError

db.Execute _
"UPDATE tblElements SET ElementOrder = " & lngCurrOrder & _
" WHERE ElementID = " & lngPrevItem, _
dbFailOnError

ws.CommitTrans

.Requery

End With

Exit_Point:
On Error Resume Next
If fInTrans Then
ws.Rollback
End If
Set db = Nothing
Set ws = Nothing
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=10974
Exit Sub

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_Point

End Sub
'----- end of code -----

NOTE: the above code assumes that the list box has its ColumnHeads
property set to No. If you're displaying column heads in the list box,
a couple of minor changes have to be made to the code.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


Reply With Quote
  #5 (permalink)  
Old 28-Jul-2006, 08:17 AM
millie.patel@gmail.com's Avatar millie.patel@gmail.com
Guest
 
Posts: n/a
   
   
Re: Order items in list box

  Donate Today!  
perfect ! thanks!

Dirk Goldgar wrote:
> wrote in message
> news:1149692178.103309.101990@g10g2000cwb.googlegr oups.com
> > The list items come from
> > tblElements
> > ElementID
> > ElementName
> > ElementOrder
> >
> > Dirk Goldgar wrote:
> >> wrote in message
> >> news:1149690155.363042.295480@y43g2000cwc.googlegr oups.com
> >>> hi all --
> >>> I have a combobox (name cboProgram);
> >>> Once the program is loaded, a listbox of associated Elements are
> >>> generated.
> >>>
> >>> The listbox (name lboElement), which has ElementID, ElementName,
> >>> ElementOrder
> >>>
> >>> When the items appear in the list box, I have the "UP" "DOWN" arrows
> >>> to the left of it to allow the user to change the ElementOrder.
> >>>
> >>> How can this be done?
> >>
> >> Where do the list items come from? If it's a table, and the table
> >> contains the fields ElementID, ElementName, and ElementOrder, then
> >> the process of moving an element up or down is going to involve
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=10974
> >> swapping the values of ElementOrder in two records -- probably via
> >> update queries-- and then requerying the list box.

>
> I hadn't written an example of this before, so I took a moment now to do
> it. Set your list box's RowSource property to this:
>
> SELECT ElementID, ElementName, ElementOrder
> FROM tblElements
> ORDER BY tblElements.ElementOrder;
>
> Name your "Up" and "Down" buttons "cmdMoveUp" and "cmdMoveDown",
> respectively.
>
> Now add the following event procedures to your form's class module:
>
> '----- start of code -----
> Private Sub cmdMoveDown_Click()
>
> On Error GoTo Err_Handler
>
> Dim lngCurrItem As Long
> Dim lngCurrOrder As Long
> Dim lngCurrRow As Long
> Dim lngNextItem As Long
> Dim lngNextOrder As Long
> Dim lngNextRow As Long
>
> Dim ws As DAO.Workspace
> Dim db As DAO.Database
>
> Dim fInTrans As Boolean
>
> With Me.lboElement
>
> If IsNull(.Value) Then
> DoCmd.Beep
> Exit Sub
> End If
>
> lngCurrRow = .ItemsSelected(0)
> If lngCurrRow = (.ListCount - 1) Then
> DoCmd.Beep
> Exit Sub
> End If
>
> lngCurrItem = .Value
> lngCurrOrder = .Column(2)
>
> lngNextRow = lngCurrRow + 1
> lngNextItem = .ItemData(lngNextRow)
> lngNextOrder = .Column(2, lngNextRow)
>
> Set ws = DBEngine.Workspaces(0)
> Set db = ws.Databases(0)
>
> ws.BeginTrans
> fInTrans = True
>
> db.Execute _
> "UPDATE tblElements SET ElementOrder = " & lngNextOrder & _
> " WHERE ElementID = " & lngCurrItem, _
> dbFailOnError
>
> db.Execute _
> "UPDATE tblElements SET ElementOrder = " & lngCurrOrder & _
> " WHERE ElementID = " & lngNextItem, _
> dbFailOnError
>
> ws.CommitTrans
>
> .Requery
>
> End With
>
> Exit_Point:
> On Error Resume Next
> If fInTrans Then
> ws.Rollback
> End If
> Set db = Nothing
> Set ws = Nothing
> Exit Sub
>
> Err_Handler:
> MsgBox Err.Description, vbExclamation, "Error " & Err.Number
> Resume Exit_Point
>
> End Sub
>
> Private Sub cmdMoveUp_Click()
>
> On Error GoTo Err_Handler
>
> Dim lngCurrItem As Long
> Dim lngCurrOrder As Long
> Dim lngCurrRow As Long
> Dim lngPrevItem As Long
> Dim lngPrevOrder As Long
> Dim lngPrevRow As Long
>
> Dim ws As DAO.Workspace
> Dim db As DAO.Database
>
> Dim fInTrans As Boolean
>
> With Me.lboElement
>
> If IsNull(.Value) Then
> DoCmd.Beep
> Exit Sub
> End If
>
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=10974
> lngCurrRow = .ItemsSelected(0)
> If lngCurrRow = 0 Then
> DoCmd.Beep
> Exit Sub
> End If
>
> lngCurrItem = .Value
> lngCurrOrder = .Column(2)
>
> lngPrevRow = lngCurrRow - 1
> lngPrevItem = .ItemData(lngPrevRow)
> lngPrevOrder = .Column(2, lngPrevRow)
>
> Set ws = DBEngine.Workspaces(0)
> Set db = ws.Databases(0)
>
> ws.BeginTrans
> fInTrans = True
>
> db.Execute _
> "UPDATE tblElements SET ElementOrder = " & lngPrevOrder & _
> " WHERE ElementID = " & lngCurrItem, _
> dbFailOnError
>
> db.Execute _
> "UPDATE tblElements SET ElementOrder = " & lngCurrOrder & _
> " WHERE ElementID = " & lngPrevItem, _
> dbFailOnError
>
> ws.CommitTrans
>
> .Requery
>
> End With
>
> Exit_Point:
> On Error Resume Next
> If fInTrans Then
> ws.Rollback
> End If
> Set db = Nothing
> Set ws = Nothing
> Exit Sub
>
> Err_Handler:
> MsgBox Err.Description, vbExclamation, "Error " & Err.Number
> Resume Exit_Point
>
> End Sub
> '----- end of code -----
>
> NOTE: the above code assumes that the list box has its ColumnHeads
> property set to No. If you're displaying column heads in the list box,
> a couple of minor changes have to be made to the code.
>
> --
> Dirk Goldgar, MS Access MVP
> www.datagnostics.com
>
> (please reply to the newsgroup)


Reply With Quote
   Click Here to Donate Now!

Support Us!
Become a Promoter!
Gurfateh ji, you can become a SPN Promoter by Donating as little as $10 each month. With limited resources & high operational costs, your donations make it possible for us to deliver a quality website and spread the teachings of the Sri Guru Granth Sahib Ji, to serve & uplift humanity. Every contribution counts. Donate Generously. Gurfateh!
ReplyPost New Topic In This Forum Stay Connected to Sikhism, Click Here to Register Now!

Bookmarks


(View-All Members who have read this thread : 0
There are no names to display.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Tools Search
Search:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On

» Active Discussions
Thought of the Moment!
Today 19:38 PM
106 Replies, 5,000 Views
Panjabi
Today 19:35 PM
10 Replies, 213 Views
BHOOTS (Ghosts) and...
Today 19:02 PM
94 Replies, 13,743 Views
Textbooks Terming Sikhs...
Today 18:52 PM
13 Replies, 172 Views
Do you believe in...
Today 18:52 PM
175 Replies, 3,615 Views
Map shows world's 'most...
Today 18:12 PM
14 Replies, 189 Views
Friends. A Testimony to...
Today 17:31 PM
3 Replies, 60 Views
Why are There so Many...
By Ishna
Today 17:28 PM
52 Replies, 4,860 Views
Nitnem Gutka - Gurmukhi...
By Ishna
Today 12:27 PM
15 Replies, 16,391 Views
Poetry Corner
Today 12:13 PM
83 Replies, 9,592 Views
Learn Punjabi Yourself...
Today 05:41 AM
15 Replies, 7,617 Views
Sikh Spokesman (ਪੰਜਾਬੀ...
Today 05:32 AM
167 Replies, 4,304 Views
The Great Imp Debate
Today 05:28 AM
32 Replies, 501 Views
Rozana Reports (ਪੰਜਾਬੀ...
Today 05:16 AM
299 Replies, 7,417 Views
Fresno Sikh Who Was...
Today 01:30 AM
0 Replies, 55 Views
» Books You Should Read...
Powered by vBadvanced CMPS v3.2.3
All times are GMT +6.5. The time now is 20:15 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2 Copyright © 2004-12, All Rights Reserved. Sikh Philosophy Network


Page generated in 0.46324 seconds with 32 queries
0