472,355 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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

3 2Bits

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 15152
32,511 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
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.
1 Week Ago #3

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

Similar topics

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...
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...
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...
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...
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...
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...
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...
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...
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...
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...

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.