ListBox - Move to next Record

cpremo

Registered User.
Local time
Today, 14:06
Joined
Jun 22, 2007
Messages
50
I have a form with an unbound ListBox that has a "Record Source" select query. The list box displays as needed. What I'm trying to do is move the selected record to the next record via code. How can I do this? The form-listbox is describe as shown:

Forms!MainMenu!ServerList

I can use code to determine the number of records:

Global MaxServers As Integer
Global Lcount As Integer
Lcount = Forms![MainMenu]!ServerList.ListCount
MaxServers = IIf(Lcount > 120, 120, Lcount)

but how do you write the code to move to the next record?????


If Grouped = -1 Then
For X = 0 To MaxServers - 1
MsgBox "This Import option will take a LONG TIME! Please be patient!", vbCritical, "Server Config File Database"
strServerName = Forms![MainMenu]!ServerList.ItemData(X)
Call ImportStep1b
Forms![MainMenu]!ServerList.???????
Next X
 
I've tried this code:

DoCmd.GoToRecord acDataForm, Forms!MainMenu!ServerList, acGoTo, 3

But it errors out because the value of "Forms!MainMenu!ServerList" is the name of the first server listed in the list box on the form.
 
What do you mean you want to "move the record"

In Access, records are not stored in any meaningful order (unless of course you give them something to order by and then enforce it). But, it is rare that you would need to physically reorder records when a query can order pretty much anything by how you define it.

What, EXACTLY, are you attempting to do (and I mean what is the purpose of your doing it this way - there may be something you haven't thought of that we can either suggest or help figure out).
 
My Main Menu has an unbound listbox. The listbox has a "Record Source" select query that shows the records in a table (four columns with x records). If I click on a record I can obtain information, say the server name which is the bound field in the listbox with this code:

strServerName = Forms![MainMenu]!ServerList.ItemData(X)

What I want to do is set the focus on the listbox to the first record and then change the focus to the next record and loop and change it to the next record in the listbox.

I know how to do the loop, what I need is how to change to the next record in the listbox until I get to the end of the records.
 
I think you want to look into the ListIndex property.
 
That was it. Thanks!

****************
Forms!MainMenu.Controls("ServerList").SetFocus
Forms!MainMenu.Controls("ServerList").ListIndex = 3
****************
 

Users who are viewing this thread

Back
Top Bottom