473,385 Members | 1,829 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.

How to requery a listbox on a form from another form

stonward
145 100+
Hi again fellows,

I've got an annoying issue I can't seem to fathom. I have a Main or 'Home' form that has a tab control which houses a listbox, which is based on a query, and shows stocklevels.

From my invoicing form, once I've done my stock update calculations (I'm working on a more elegant solution), I need to requery the listbox on the main form to ensure the stock values shown are up to date.

I've tried 'everything'! Open and close the main form from the invoice form, requery the listbox from the invoice form, requery the listbox once the main form has the focus etc. Clicking my reset button on the main form updates the listbox just fine - I've tried cmdReset_Click from the invoice form (worked in Access 97!), but gives an error in 2007.

Sorry its so mundane, yet long to write out! Can someone help?

Many thanks.

stonward
Jan 30 '13 #1

✓ answered by TheSmileyCoder

Ooops! Does tab send the post?
No but Tab (Which switches focus to the Post Reply Button) followed by a Enter or spacebar will submit :)

I don't use tab controls much, but no I don't think you need to include the tab control in the syntax.

Try this:
Expand|Select|Wrap|Line Numbers
  1. Forms!frm_Main.List55.Requery
P.s. Save yourself future headache and give the listbox a proper name!

13 11068
Rabbit
12,516 Expert Mod 8TB
Show us the code that you're using to refresh the list box. Also, what is the text of the error message?
Jan 30 '13 #2
stonward
145 100+
I don't get any error messages, Rabbit. The latest thing I tried was DoCmd.Requery(...listbox55) in the Close event of the invoice form.

I'm guessing now that I'm going to have to fully close the invoice form before requerying the listbox. Essentially, I've tried the Requery command at just about every event!

It's feels such a silly, annoying issue (unlike my struggles with Allen Brownes 'onHand' code!), and there aren't many ways really to use requery.

Thanks for your time - especially at this time.

Regards,

stonward
Jan 31 '13 #3
NeoPa
32,556 Expert Mod 16PB
It's perfectly possible to do by using :
Expand|Select|Wrap|Line Numbers
  1. Call {Reference to ListBox control}.Requery()
The only problem is determining the {Reference to ListBox control}. Referring to Items on a Sub-Form should help with that. If you struggle we can help, but only if you give us all the details you'll need for the reference.
Jan 31 '13 #4
Rabbit
12,516 Expert Mod 8TB
Post 1, paragraph 3 (not counting the greeting), last line. You say you get an error. Now you're saying you're not getting an error.

Also, this:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.Requery(...listbox55)
is not valid code so it should have thrown an error.

Per NeoPa's post, the most likely cause is an invalid reference to a control, which is why I wanted to see your requery code.
Jan 31 '13 #5
TheSmileyCoder
2,322 Expert Mod 2GB
Whats the name of the form, name of the listbox control, and is the listbox in a subform?
Jan 31 '13 #6
stonward
145 100+
Thanks for your replies.

I only got an error when I tried to 'remotely' click a button on my main form - cmdReset_Click.

The listbox is in a two page tab control, but not a subform. The main form is frm_Main, the listbox list55.

So to be completely disambiguous about my listbox:
Form_frm_Main.List55.Requery is about as explicit as I can get I think. The lisbox is on page one of a tab control: I dont have to reference that do I?

Appreciative,

stonward
Jan 31 '13 #7
TheSmileyCoder
2,322 Expert Mod 2GB
Ooops! Does tab send the post?
No but Tab (Which switches focus to the Post Reply Button) followed by a Enter or spacebar will submit :)

I don't use tab controls much, but no I don't think you need to include the tab control in the syntax.

Try this:
Expand|Select|Wrap|Line Numbers
  1. Forms!frm_Main.List55.Requery
P.s. Save yourself future headache and give the listbox a proper name!
Jan 31 '13 #8
Seth Schrock
2,965 Expert 2GB
I don't use tab controls much, but no I don't think you need to include the tab control in the syntax.
You are correct Smiley.
Jan 31 '13 #9
stonward
145 100+
ha ha! Yes, and for anyone else listening, have a firm naming system. I have, but I slip sometimes when I'm fighting to get something done - and I pay for it every time!

Thanks guys,

stonward
Jan 31 '13 #10
TheSmileyCoder
2,322 Expert Mod 2GB
You are welcome.

Note that Form_Frm_main is the reference to class object of your form.

When you open the form, then an object of that class gets added to the Forms collection, with a key Frm_Main. Thats why you can use the notations
Forms!Frm_Main
or
Forms("Frm_Main")

You can argue that the object in the forms collection is a Form_frm_Main but that within the collection it has been assigned the key frm_Main. (At least that is my basic understanding of the underlying mechanics).


Per default Access only opens 1 object of each form class, but it is possible to have the same form open multiple times, although it requires a slight bit more work.
Jan 31 '13 #11
NeoPa
32,556 Expert Mod 16PB
Stonward:
So to be completely disambiguous about my listbox:
Form_frm_Main.List55.Requery is about as explicit as I can get I think.
Good answer, but strangely, more helpful information would be where it is relative to the code that's running. If, as seems likely, the code is running from somewhere on the same form (within that same form's associated module) then referring to it using an external reference is not to be recommended at all. That simply adds to your maintenance overhead, and is easily avoided using the Me reference.

Thus, in that scenario (Most definitely doesn't work from outside of the scope of that same form.) the code would be :
Expand|Select|Wrap|Line Numbers
  1. Call Me.List55.Requery
NB. The external reference will still work of course. It is simply an overly clumsy way to code it in those circumstances.
Jan 31 '13 #12
stonward
145 100+
NeoPa; You've just taught me something new. I didn't know you can call a method like that. Be assured I'll be using that!

Many thanks again,

stonward
Feb 5 '13 #13
NeoPa
32,556 Expert Mod 16PB
Very pleased to hear it :-)

I find most of my event procedures start with With Me and end with End With. If you don't know about With then that's another you would probably benefit from picking up.
Feb 5 '13 #14

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

Similar topics

3
by: fh1996 | last post by:
Form.Owner and Form.Parent, what's the difference between them? Form.ShowDialog() and Form.Show(), when to use which? Form.Activated(), what does it mean when saying a Form is "activated"? ...
1
by: Riun | last post by:
My Main form acts as a Menu. It has 3 CmdButtons which directs to 3 Forms (Form 1, Form 2, Form 3). Form 1 also directs to the next, etc. My problem is that when I Click on the CmdButton that...
11
blyxx86
by: blyxx86 | last post by:
I can't seem to get this figured out. I am trying to requery another form after adding new information to a table that a cboList is created from. So, I have a combo box that has Sales personnel,...
2
by: bobdydd | last post by:
Hi All Access 2007 I have a form with a ListBox called "ListContactTasks" DoubleClicking the ListBox opens another form called "frmContact" at a particular record corresponding to the one in...
1
by: jebtrillion | last post by:
I want to fill a listbox that is on another form. I'm not sure how to declare it so the main form can see it. Help
7
by: Randy | last post by:
Hi, I've got a listbox on a form that gets updated by opening another form for data entry. Once the user enters the new item name and clicks "accept", the data entry form closes and the original...
1
by: kaosx5 | last post by:
I have a report sceniro where I have the user select a Report(acutally it is a macro but didn't want to confuse the user) off of Form1. When the user double clicks the Macro name it opens Form 2...
5
by: lukasmazur | last post by:
Hi I have a problem with using listBox1. I have a two forms form1 and form2. In form1 are controls listBox1, textBox1 and button witch creating object of class Form2. In class Form2 I create a...
3
by: ziycon | last post by:
I'm looking to add items on a listbox on form A from class B which is called from form A. I just don't know how to say add them to the listbox on the active form A from the class B!? It's in C#, can...
4
by: Organizer | last post by:
I am using Microsoft Access 2007. I have a list in a dropdown combobox (Field_One) in a form (Form_One). Users have the option to click a button if the item they need does not appear in the combobox,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
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,...
0
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,...
0
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...

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.