472,358 Members | 1,729 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,358 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 37650
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,511 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,511 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,511 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,511 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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
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...
0
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...
1
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...
2
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...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
Oralloy
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++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

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.