473,406 Members | 2,451 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,406 software developers and data experts.

How to requery another object on another form?

blyxx86
256 100+
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, and i have another form that lets me add sales personnel to the table of all the sales team. (Name, number, etc...)

But when I open up the main form (with the combo box of Sales Personnel) and then open the form to add new members, or edit the members, I can not seem to make a piece of code that will requery the main combo box.

I have tried the following with no success...

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command15_Click()
  2. Dim cboSales As Control
  3. cboSales = Forms!Main.Sales
  4. cboSales.Requery
  5. End Sub
  6.  
Run time error '2465'
That doesn't work.

I tried...
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command15_Click()
  2. Dim Forms!Main.Sales As Control
  3. Forms!Main.Sales.Requery
  4.  
  5. End Sub
  6.  
That one is just filled with errors.

I tried to do a:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command15_Click()
  2. Dim testReqSale As String
  3. testReqSale = Forms!Main.Sales
  4. DoCmd.Requery(testReqSale)
  5.  
  6. End Sub
  7.  
Again, no success and more errors.

I suppose I could put a Requery command on the link to the form to add sales personnel, but that seems ineffective and the form could be possibly opened otherwise.
Dec 6 '06 #1
11 38092
MMcCarthy
14,534 Expert Mod 8TB
Try this ...

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command15_Click()
  2.  
  3.    Forms!Sales!cboSales.Requery
  4.  
  5. End Sub
  6.  
Dec 6 '06 #2
blyxx86
256 100+
Try this ...

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command15_Click()
  2.  
  3.    Forms!Sales!cboSales.Requery
  4.  
  5. End Sub
  6.  
Now I have another error.

I get an error message saying that this can not be done within the database's current view. (Because the "Sales" window is not open.)

What type of code would I put in this?

Would I place an "On Error Continue" ??

I'm not too sure what to do on this one, but that code did work, but only if that window is open. If it's not open, I get an error.
Dec 6 '06 #3
MMcCarthy
14,534 Expert Mod 8TB
Now I have another error.

I get an error message saying that this can not be done within the database's current view. (Because the "Sales" window is not open.)

What type of code would I put in this?

Would I place an "On Error Continue" ??

I'm not too sure what to do on this one, but that code did work, but only if that window is open. If it's not open, I get an error.
You're right the Sales form has to be open for it to work. One option would be to open the form and close it after.

Expand|Select|Wrap|Line Numbers
  1.  
  2. DoCmd.OpenForm "Sales"
  3. Forms!Sales!cboSales.Requery
  4. DoCmd.Close acForm, "Sales"
  5.  
Dec 6 '06 #4
nico5038
3,080 Expert 2GB
A requiry in Access doesn't always give the needed result.
I personally prefer to use:
cboSales.rowsource =cboSales.rowsource
This guarantees a requiry.

When you use a "normal" form for the addition you can add the statement in the form's OnActivate event. Thus the combobox will always be refreshed when the form is activated. When you have a "popup" form, the OnActivate of the original form isn't triggered, don't ask me why <LOL>

Nic;o)
Dec 6 '06 #5
NeoPa
32,556 Expert Mod 16PB
Now I have another error.

I get an error message saying that this can not be done within the database's current view. (Because the "Sales" window is not open.)

What type of code would I put in this?

Would I place an "On Error Continue" ??

I'm not too sure what to do on this one, but that code did work, but only if that window is open. If it's not open, I get an error.
Yes.
An 'On Error GoTo ...' is the best thing to do here.
If it isn't already open there's really no point in requerying. It will happen if/when it's opened.
Dec 7 '06 #6
NeoPa
32,556 Expert Mod 16PB
A requiry in Access doesn't always give the needed result.
I personally prefer to use:
cboSales.rowsource =cboSales.rowsource
This guarantees a requiry.

When you use a "normal" form for the addition you can add the statement in the form's OnActivate event. Thus the combobox will always be refreshed when the form is activated. When you have a "popup" form, the OnActivate of the original form isn't triggered, don't ask me why <LOL>

Nic;o)
With a popup form, the idea is 'logically' that the calling form is not de-activated first, but that the popup form goes on top (like a MsgBox). When the Popup is closed the calling form 'stays' activated. A little strange to be sure.
Dec 7 '06 #7
blyxx86
256 100+
Yes.
An 'On Error GoTo ...' is the best thing to do here.
If it isn't already open there's really no point in requerying. It will happen if/when it's opened.
What exactly would it say? I've never seen that before...

[code]
On Error Goto what?
[code]
Dec 7 '06 #8
NeoPa
32,556 Expert Mod 16PB
What exactly would it say? I've never seen that before...

[code]
On Error Goto what?
[code]
On Error Statement


Enables an error-handling routine and specifies the location of the routine within a procedure; can also be used to disable an error-handling routine.

Syntax

On Error GoTo line

On Error Resume Next

On Error GoTo 0

The On Error statement syntax can have any of the following forms:

Statement Description
On Error GoTo line Enables the error-handling routine that starts at line specified in the required line argument. The line argument is any line label or line number. If a run-time error occurs, control branches to line, making the error handler active. The specified line must be in the same procedure as the On Error statement; otherwise, a compile-time error occurs.
On Error Resume Next Specifies that when a run-time error occurs, control goes to the statement immediately following the statement where the error occurred where execution continues. Use this form rather than On Error GoTo when accessing objects.
On Error GoTo 0 Disables any enabled error handler in the current procedure.
Actually you would use 'On Error Resume Next' and just continue as if nothing had happened.
Dec 7 '06 #9
blyxx86
256 100+
Actually you would use 'On Error Resume Next' and just continue as if nothing had happened.
I just place that in front of the other code, correct? I appreciate the help on this.
Dec 7 '06 #10
MSeda
159 Expert 100+
I know I'm jumping in kind of late here, but have you tried setfocus. In order to requery an object the form it's on has to have focus.

Try

Private Sub Command15_Click()

Forms![Main].SetFocus
DoCmd.Requery "Sales"

End Sub
Dec 7 '06 #11
NeoPa
32,556 Expert Mod 16PB
I just place that in front of the other code, correct? I appreciate the help on this.
Yes.
But you should really have an
Expand|Select|Wrap|Line Numbers
  1. On Error GoTo 0
afterwards as well.
See the help on this (mainly posted above but in full from Access VBA Help) as it's very important to understand (and to use).
Dec 7 '06 #12

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

Similar topics

0
by: Michelle | last post by:
Hi all I have a main form which has a combo box and a subform. The two forms are linked by ShiftPatternName which is basically the value in the combo. the combo has the following code ...
6
by: Tim Marshall | last post by:
Here's the situation. A form, frmSetUp, with a subform control called subExplain with a source object form frmSetUpSubDefineSides. The source object is a bound form, displaying a few records, no...
4
by: Dave Boyd | last post by:
Hi, I have two very similar forms each with a subform. The main form gets a few fields from the user and passes this back to a query that the subform is bound to. The requery is done when the...
2
by: F. Michael Miller | last post by:
I need to requery a subform from a third form and can't seem to get it to work. frmForm1 has frmAddress as a subform. The button cmdReviseAddress opens the form frmUpdateAddress where all of my...
22
by: Br | last post by:
First issue: When using ADPs you no longer have the ability to issue a me.refresh to save the current record on a form (the me.refresh does a requery in an ADP). We usually do this before...
1
by: BartonConstruction | last post by:
Greetings all, I have a main form (frmClients) with two subforms (subVisits) (subAccount). I got the subforms to reflect what the main form is showing by linking master and child fields (I...
14
by: Kurt | last post by:
I have an unbound main form with an unbound subform. frmProjects fsubProjectList Using combo boxes, the user can select several search criteria on frmProjects and then click a command button....
11
by: mrowe | last post by:
I am using Access 2003. (I am also using ADO in the vast majority of my code. I recently read a post that indicated that ADO is not all that is was initially cracked up to be. In the back of my...
2
by: Lyn | last post by:
Hi, I am using a form (FormA) to list the records in a recordset. In the FormA footer, I have an "Add" command button that opens a new form (FormB) modally which is used to input and save a new...
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: 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
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
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
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.