[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Next record button based on combo box

Posted on 2014-02-10
14
Medium Priority
?
937 Views
Last Modified: 2014-02-19
I am putting together a database form.  I have a next record button.  Right now the next record button goes to the next record from a table.  But,  I need the next record button to be based on the records shown in the right combo box.  

At the top of the contact form.  There are three combo boxes.  I need the next record button to go to the next record of the records in the third right combo box.  

See attached sample database.
1.accdb
0
Comment
Question by:lehi52
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 7
14 Comments
 
LVL 10

Expert Comment

by:Gozreh
ID: 39848059
you can use ListIndex example (you should change it to your field names)

to go next
ComboName.SetFocus
If ComboName.ListIndex <> ComboName.ListCount - 1 Then
        ComboName.ListIndex = ComboName.ListIndex + 1
      Else
        ComboName.ListIndex = 0
      End If
End Sub

Open in new window

and to go back
ComboName.SetFocus
If ComboName.ListIndex <> 0 Then
        ComboName.ListIndex = ComboName.ListIndex - 1
      Else
        ComboName.ListIndex = ComboName.ListCount - 1
      End If
End Sub

Open in new window

0
 

Author Comment

by:lehi52
ID: 39848120
I get an error when I change the name in the code to the name of the combo box.  This code refers to the "display" combo box.   I am sure I did something wrong. I posted the code into the VBA code.  Does the code need to be put into a specific event procedure to work?

display.SetFocus
If display.ListIndex <> display.ListCount - 1 Then
        display.ListIndex = display.ListIndex + 1
      Else
        display.ListIndex = 0
      End If
End Sub
------------------------------------------------------------
display.SetFocus
If display.ListIndex <> 0 Then
        display.ListIndex = display.ListIndex - 1
      Else
        display.ListIndex = display.ListCount - 1
      End If
End Sub

Open in new window

0
 
LVL 10

Expert Comment

by:Gozreh
ID: 39848301
Where did you put this code ?
Private Sub Command51_Click()
   Me.display.SetFocus
   If Me.display.ListIndex <> Me.display.ListCount - 1 Then
      Me.display.ListIndex = Me.display.ListIndex + 1
   Else
      Me.display.ListIndex = 0
   End If
End Sub

Open in new window

Private Sub Command52_Click()
   Me.display.SetFocus
   If Me.display.ListIndex <> 0 Then
      Me.display.ListIndex = Me.display.ListIndex - 1
   Else
      Me.display.ListIndex = display.ListCount - 1
   End If
End Sub

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:lehi52
ID: 39848355
I just put it into the VBA code.  no where specifically.  I just added it into there.   It did not work with those changes.
0
 

Author Comment

by:lehi52
ID: 39848366
It does work but it spits out an error.  Run-Time Error '7777' You've used the List Index property incorrectly.

It goes to the next record and cycles through only those names,  but the issue is after I click next each time the error pops up.
0
 
LVL 10

Expert Comment

by:Gozreh
ID: 39848422
please upload your sample
0
 

Author Comment

by:lehi52
ID: 39848435
Here you go.
2.accdb
0
 
LVL 10

Expert Comment

by:Gozreh
ID: 39848461
Go to the VBA (Press Alt+F11 from main application), then select debug / compile database.
when you will get an error comment that line, and compile again.
then test the code again.
0
 

Author Comment

by:lehi52
ID: 39848474
Now it cycles through, but it only changes the name in the combo box,  and does not change the entire record displayed on the form.
0
 
LVL 10

Expert Comment

by:Gozreh
ID: 39848477
add after the code display_AfterUpdate
Private Sub Command51_Click()
   Me.display.SetFocus
   If Me.display.ListIndex <> Me.display.ListCount - 1 Then
      Me.display.ListIndex = Me.display.ListIndex + 1
   Else
      Me.display.ListIndex = 0
   End If
   display_AfterUpdate 
End Sub

Open in new window

0
 

Author Comment

by:lehi52
ID: 39848502
Gives an error again after adding that.  Same error as before.
3.accdb
0
 
LVL 10

Accepted Solution

by:
Gozreh earned 2000 total points
ID: 39848547
Just change to this
Private Sub Command51_Click()
   On Error Resume Next
   If Me.display.ListIndex <> Me.display.ListCount - 1 Then
      Me.display.SetFocus
      Me.display.ListIndex = Me.display.ListIndex + 1
   Else
      Me.display.ListIndex = 0
   End If
   DoCmd.SearchForRecord , , acFirst, "[ContactID] = " & Nz(Me.display, 0)
End Sub

Open in new window

4.accdb
0
 
LVL 10

Expert Comment

by:Gozreh
ID: 39848560
Just to let you know, you should compact your database regularly, the file you uploaded is 4.9MB and the file i uploaded is 1.5MB.
http://office.microsoft.com/en-us/access-help/compact-and-repair-an-access-file-HP005187449.aspx
0
 

Author Closing Comment

by:lehi52
ID: 39848578
Great solution.   Thank you.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question