473,729 Members | 2,331 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Refresh ComboBox After Adding New Values via a Separate Form

31 New Member
Hi,

I've been having a similar issue to what is described in the "refresh a form" post with a ComboBox that is not being refreshed after adding a new value on a seperate form. The second form is being opened via the standard DoCmd call.

I've tried adding Requery in AfterUpdate, Form_Current, etc. to no avail.... The test form has the combobox and a command button.

Here's my test code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdAddCatgCd_Click()
  2. On Error GoTo Err_cmdAddCatgCd_Click
  3.  
  4.     Dim stDocName As String
  5.     Dim stLinkCriteria As String
  6.  
  7.     stDocName = "subfrmHierCatgCd"
  8.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  9.  
  10. Exit_cmdAddCatgCd_Click:
  11.     Exit Sub
  12.  
  13. Err_cmdAddCatgCd_Click:
  14.     MsgBox Err.Description
  15.     Resume Exit_cmdAddCatgCd_Click
  16. End Sub
  17.  
  18. Private Sub Form_AfterUpdate()
  19.     Me.Combo21.Requery
  20. End Sub
  21.  
  22. Private Sub Form_Current()
  23.     Me.Combo21.Requery
  24. End Sub
cmdAddCatgCd_Cl ick opens another form to maintain the code values that are populated in Combo21.

So far, the only way I've been able to get this to work is by adding a "Refresh" command button with the following code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command25_Click()
  2. On Error GoTo Err_Command25_Click
  3.  
  4.     Me.Combo21.Requery
  5.  
  6. Exit_Command25_Click:
  7.     Exit Sub
  8.  
  9. Err_Command25_Click:
  10.     MsgBox Err.Description
  11.     Resume Exit_Command25_Click
  12.  
  13. End Sub
I'd prefer having the requery happen automatically for both forms and subforms.....

Thanks, Ed.
May 7 '07 #1
34 20221
Rabbit
12,516 Recognized Expert Moderator MVP
Hi,

I've been having a similar issue to what is described in the "refresh a form" post with a ComboBox that is not being refreshed after adding a new value on a seperate form. The second form is being opened via the standard DoCmd call.

I've tried adding Requery in AfterUpdate, Form_Current, etc. to no avail.... The test form has the combobox and a command button.

Here's my test code:

Private Sub cmdAddCatgCd_Cl ick()
On Error GoTo Err_cmdAddCatgC d_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "subfrmHierCatg Cd"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdAddCatg Cd_Click:
Exit Sub

Err_cmdAddCatgC d_Click:
MsgBox Err.Description
Resume Exit_cmdAddCatg Cd_Click
End Sub

Private Sub Form_AfterUpdat e()
Me.Combo21.Requ ery
End Sub

Private Sub Form_Current()
Me.Combo21.Requ ery
End Sub

cmdAddCatgCd_Cl ick opens another form to maintain the code values that are populated in Combo21.

So far, the only way I've been able to get this to work is by adding a "Refresh" command button with the following code:

Private Sub Command25_Click ()
On Error GoTo Err_Command25_C lick

Me.Combo21.Requ ery

Exit_Command25_ Click:
Exit Sub

Err_Command25_C lick:
MsgBox Err.Description
Resume Exit_Command25_ Click

End Sub

I'd prefer having the requery happen automatically for both forms and subforms.....

Thanks, Ed.
Have you tried the solutions that were posted in that other thread?
May 7 '07 #2
bitsnbytes64
31 New Member
Have you tried the solutions that were posted in that other thread?
Yes. Originally, I replied to that post to imply this but NeoPa told me I had to start a new thread so I did.

I think part of the problem I'm having is that there's no direct link between the forms. Once the second form is opened, the code being executed in the main form (DoCmd) continues to completion. It doesn't wait for the user to close the second form....

Code from Command Button to open second form:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdAddCatgCd_Click()
  2. On Error GoTo Err_cmdAddCatgCd_Click
  3.  
  4.     Dim stDocName As String
  5.     Dim stLinkCriteria As String
  6.  
  7.     stDocName = "subfrmHierCatgCd"
  8.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  9.  
  10. Exit_cmdAddCatgCd_Click:
  11.     Exit Sub
  12.  
  13. Err_cmdAddCatgCd_Click:
  14.     MsgBox Err.Description
  15.     Resume Exit_cmdAddCatgCd_Click
  16. End Sub
  17.  
Any ideas ?

Thanks, Ed.
May 7 '07 #3
Rabbit
12,516 Recognized Expert Moderator MVP
What about putting the refresh/requery code in the second form? Perhaps in the On Close event it can also refresh/requery the first form.
May 7 '07 #4
Denburt
1,356 Recognized Expert Top Contributor
I saw the other thread Bits and don't take offense to the tone that you might think someone came across in, we all see what is typed but what we don't see are facial expressions etc. Many times when I was a forum noob (new guy) I took a completely harmless comment or even a stern one, and thought it seemed harsh. Most of us here (if not all) are simply volunteers helping each other.

On to your issue as Rabbit stated use the "on close" event of the second form to save the record on the second form, and then requery the main forms combo box.
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunCommand (acCmdSelectRecord)
  2.     DoCmd.RunCommand (acCmdSaveRecord)
  3. Forms!FirstForm!ComboBox1.requery
This should resolve your problem. Also a link to the other thread would be nice I am sure you were probably looking for a way to do that. It's the round world looking thing next to the square pic in the toolbar on top.

http://www.thescripts.com/forum/thread639998.html
May 7 '07 #5
bitsnbytes64
31 New Member
I saw the other thread Bits and don't take offense to the tone that you might think someone came across in, we all see what is typed but what we don't see are facial expressions etc. Many times when I was a forum noob (new guy) I took a completely harmless comment or even a stern one, and thought it seemed harsh. Most of us here (if not all) are simply volunteers helping each other.

On to your issue as Rabbit stated use the "on close" event of the second form to save the record on the second form, and then requery the main forms combo box.

Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunCommand (acCmdSelectRecord) DoCmd.RunCommand (acCmdSaveRecord) Forms!FirstForm!ComboBox1.requery
  2.  

This should resolve your problem. Also a link to the other thread would be nice I am sure you were probably looking for a way to do that. It's the round world looking thing next to the square pic in the toolbar on top.

http://www.thescripts.com/forum/thread639998.html
First off, thanks for the advice !

Regarding the questions I had.... If the user does not close the form even after adding a record or two, the Requery would not get executed as the Close event was not triggered ? I may have to add that to other events as well (most likely as a public routine) ?

Additionally, for every form with that combobox that calls the maint form I'm assuming I'd have to add a Requery statement for each and every form ?

Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunCommand (acCmdSelectRecord) DoCmd.RunCommand (acCmdSaveRecord) Forms!FirstForm!ComboBox1.requery Forms!SecondForm!ComboBox1.requery Forms!ThirdForm!ComboBox1.requery Forms!FourthForm!ComboBox1.requery Forms!SubForm1!ComboBox1.requery Forms!SubForm2!ComboBox1.requery
  2.  

Will an error be generated if a form that's being requeried (e.g. FourthForm) is not open ?

Thanks for the help !

Ed.
May 8 '07 #6
Denburt
1,356 Recognized Expert Top Contributor
Why would you want so many forms open at once? That approach does not seem to be very efficient at all. You can check to see if a form is open I utilize the following function.

Expand|Select|Wrap|Line Numbers
  1. Function IsLoaded(strFrmName As String) As Boolean
  2.     Const conFormDesign = 0
  3.     Dim intX As Integer
  4.     IsLoaded = False
  5.     For intX = 0 To Forms.Count - 1
  6.         If Forms(intX).FormName = strFrmName Then
  7.             If Forms(intX).CurrentView <> conFormDesign Then
  8.                 IsLoaded = True
  9.                 Exit Function
  10.             End If
  11.         End If
  12.     Next
  13. End Function
Then simply call the function:
Expand|Select|Wrap|Line Numbers
  1. if isloaded("YourFormName") then Forms!YourFormName.requery
May 8 '07 #7
bitsnbytes64
31 New Member
Why would you want so many forms open at once? That approach does not seem to be very efficient at all. You can check to see if a form is open I utilize the following function.

Expand|Select|Wrap|Line Numbers
  1. Function IsLoaded(strFrmName As String) As Boolean
  2.     Const conFormDesign = 0
  3.     Dim intX As Integer
  4.     IsLoaded = False
  5.     For intX = 0 To Forms.Count - 1
  6.         If Forms(intX).FormName = strFrmName Then
  7.             If Forms(intX).CurrentView <> conFormDesign Then
  8.                 IsLoaded = True
  9.                 Exit Function
  10.             End If
  11.         End If
  12.     Next
  13. End Function
Then simply call the function:
Expand|Select|Wrap|Line Numbers
  1. if isloaded("YourFormName") then Forms!YourFormName.requery
Thanks, I'll try your suggestion.

Not all of the forms will be opened at once, hence my question about when the form is not opened. The user should only have the main data entry form and the code maintenance form opened at a given time....

Thanks again, Ed.
May 8 '07 #8
bitsnbytes64
31 New Member
Thanks, I'll try your suggestion.

Not all of the forms will be opened at once, hence my question about when the form is not opened. The user should only have the main data entry form and the code maintenance form opened at a given time....

Thanks again, Ed.
Hi Denburt,

A quick question. I have a routine that checks is a Form is opened already but it doesn't use a FOR loop. It uses SysCmd to check for the specified form. Is one better than the other ?

Expand|Select|Wrap|Line Numbers
  1. Public Function FormIsOpen(ByVal strFormName As String) As Boolean
  2.  
  3. Const conDesignView = 0
  4. Const conObjStateClosed = 0
  5.  
  6. FormIsOpen = False
  7. If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then
  8.     If Forms(strFormName).CurrentView <> conDesignView Then
  9.         FormIsOpen = True
  10.     End If
  11. End If
  12.  
  13. End Function
  14.  
Thanks, Ed.
May 8 '07 #9
Denburt
1,356 Recognized Expert Top Contributor
I think your method would be much more efficient, thanks for posting it. A lot of my code including the code I posted travels around in my databases I start a new db and the first thing I do is import several modules and off I go. The code I posted has been with me since I started with MS Access and that was way to many years now.... I think I found it on one of Microsoft's examples somewhere.
May 8 '07 #10

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

Similar topics

5
4662
by: Aaron Ackerman | last post by:
I have a bound combobox the appears on a cell within the column of my bound grid when the user clicks on a cell n(In my vb.net WinForm app). I am trying to allow the adding of an item to that bound combo by allowing the user to dynamically type in the new value directly in the combo box whcih in turn updates the lookup table and then when they have finished leaves that particular cell on the grid with the correct value. Seems...
1
1306
by: ECathell | last post by:
I am getting an unspecified error when adding a windows form to a project. New project, old project. Doesn't matter. Also happens for user control. All the message box says is Unspecified Error. -- --Eric Cathell, MCSA
3
6079
by: awebguynow | last post by:
in other words, Can I make client side mod's before I submit a form and Post ? I guess its just a matter of cycling through the form elements and setting value to null (or empty string) for those that did not Change ( using onChange ).
0
5523
by: reloader | last post by:
Hi all, I would like to ask you about combobox refershing. My code is: <title>none</title> <body> <table border="1" width="100%" cellspacing="0" cellpadding="2"> <% dim m_DB
1
2149
by: BASSPU03 | last post by:
I've set my combobox to operate according to this option: "Find a record on my form based on a value I selected from my combobox." When I select a value from the combobox, I can see that the record on the navigation bar changes accordingly. (Example: Select "2000" and record is 1 of 21; select 2001 and record is 2 of 21; and so forth.) Unfortunately, when I press "Tab" from that combobox on the main form to a field in the subform and...
2
3163
by: billa856 | last post by:
Hi, My project is in MS Access. In that I have one Form in which I have some Comboboxes. 1st one is Independent, 2nd one is dependent on first one, 3rd one is dependent on 1st and 2nd both. After I load the form when I select an item from 1st one it will generate list for 2nd one, then I select an item from 2nd one it will generate list for 3nd one. Uptil this, all r done well. But after these selection if I change the selection of 1st...
1
1449
by: Mel | last post by:
On the SERVER SIDE, I need to get some values from form Elements and save the values into a file. Is this possible using Javascipt ? any exmple is highly appreciated
1
6514
by: hollywood115 | last post by:
Hey guys. I have a quick question... its very simple but i cant find a way to do it.. I need to add items to a combobox in a windows form... i need to have a name, and a value to go with it so they're associated with one another. whats the easiest way i can do this? i thought of creating a new class to handle it, but im sure c# has a way of doing that already.... thanks for your help.
5
2129
by: AccessHunter | last post by:
Hi, I have a continous form that displays Name and Address of Suppliers. In the form there is a combo box for 'Active Address' and 10 other text boxes. All the fields coem from one table, "Primary Suppliers". The combobox is for 'Active Address' with values 'Yes' and 'No'.Control source of the form is, Select * from PrimarySuppliers where ="Yes". I want the form to display only the Suppliers who has 'Active address' = "Yes".If user selects...
0
8917
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8761
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9281
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9200
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2680
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.