473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Command button to go to previous record in an Unbound combo box

3 2Bits
Hi,

I have an unbound combo box that I would like to navigate back and forth through the records populated in the combo box. I currently have an advance button thanks to this post here: https://bytes.com/topic/access/answers/649962-advancing-unbound-combo-box. Does anyone know how to do the opposite and create an previous record VBA code?

This is the code I am using for my advance:
Expand|Select|Wrap|Line Numbers
  1. Function AdvanceCombo(strForm As String, strControl As String)
  2. 'This function clears all entries on all listboxes on the form strForm
  3. Dim c As Control
  4. Dim F As Form
  5. Dim I As Long
  6. Dim cValue As String
  7. Set F = Forms(strForm)
  8. Set c = F(strControl)
  9. cValue = c.Value
  10. For I = 0 To c.ListCount - 1
  11. If c.ItemData(I) = cValue Then c.Value = c.ItemData(I + 1)
  12. Next I
  13. End Function
and the command button:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdnext_Click()
  2. AdvanceCombo Me.Name, "cboName"
  3. cboName_AfterUpdate
  4. End Sub
Thank you!
Apr 28 '23 #1
2 17291
NeoPa
32,556 Expert Mod 16PB
Hi Aviqq.

Welcome to Bytes.com :-)

You could simply change the code on line #11 to :
Expand|Select|Wrap|Line Numbers
  1. If c.ItemData(I) = cValue Then c.Value = c.ItemData(I - 1)
Notive, neither version handles coming to the end of the list very tidily.
Apr 28 '23 #2
Aviqq
3 2Bits
Thank you it worked!

However, I get a Run-time error '94': Invalid use of Null. This occurs when nothing has been selected yet in the combo box. When I click debug, "cValue = c.Value" is highlighted. Could I make it so when nothing is selected and I click the advance button, it goes to first record? and when I click previous button it goes to the last?

Also, Is there any way I could make it so that the advance and previous buttons wrap to begging or end?

Thanks so much for the help.
May 24 '23 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Megan | last post by:
I'm using an unbound combo box on a form as a record selector. I'm using the combo box to choose certain types of music, i.e. Alternative, Pop, Rock, etc…and then run a report based on the...
14
by: Kevin | last post by:
A couple of easy questions here hopefully. I've been working on two different database projects which make use of multiple forms. 1. Where's the best/recommended placement for command buttons...
6
by: Rig20 | last post by:
Hello, I’m sure this is a relatively easy fix, but I have an unbound combo box on a form that runs numerous queries in the After Update section. Everything there works fine. All I need to do is...
7
by: kashif khan | last post by:
Hi All, I have created a form in MSAccess and linked that form with a table. now in the run mode if i am entering any thing in the textbox and closing the form with out clicking on add record...
1
by: kashif khan | last post by:
Hi All, I have created a form in MSAccess and linked that form with a table. now in the run mode if i am entering any thing in the textbox and closing the form with out clicking on add record...
2
by: iamdennis | last post by:
Hi all. I stuck here and need some help. I have created a combo box which contains a list of links to external PDF files. I also created a OPEN command button next to the combo box. I want to...
5
by: Kat7 | last post by:
Hello out there! I've turned into an internet junkie trying to find the answer to this seemingly simple question. Every suggestion I try has failed. Form wizard, VBA, macros, modules ... I never...
4
beacon
by: beacon | last post by:
Hi everybody, I have a main form, frmDeficiency, that has a tab control, deficiencyTabControl, that has a subform, fsubEpisodeDetail, on page 2 of the tab control. I also have a command button...
1
by: mshakeelattari | last post by:
Hi, I have an unbound form with some unbound controls such as combo boxes or textboxes, in MS Access 2013. I have a report with the similar controls. I do open the report from the form by a command...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.