473,385 Members | 1,154 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,385 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 17287
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.