473,700 Members | 2,845 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to requery another object on another form?

blyxx86
256 Contributor
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 38186
MMcCarthy
14,534 Recognized Expert Moderator MVP
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 Contributor
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 Recognized Expert Moderator MVP
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 Recognized Expert Specialist
A requiry in Access doesn't always give the needed result.
I personally prefer to use:
cboSales.rowsou rce =cboSales.rowso urce
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,569 Recognized Expert Moderator MVP
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,569 Recognized Expert Moderator MVP
A requiry in Access doesn't always give the needed result.
I personally prefer to use:
cboSales.rowsou rce =cboSales.rowso urce
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 Contributor
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,569 Recognized Expert Moderator MVP
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 Contributor
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

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

Similar topics

0
429
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 Me.RecordsetClone.FindFirst " = '" & Me! & "'"
6
5473
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 edit, adds, filters, etc, are permitted on the subform. An add or edit button on the subform is clicked opening an unbound form, frmSetUpSideAdd, (populated with values from the above subform if this is an edit of an existing record) for data...
4
7014
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 user enters the last qualifying field on the main form. In one case this works fine, the subform shows the data the user wants to update -- which means showing all the data put in previously (ie showing this via the requery and the continuous...
2
10893
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 validation work is done and the new record is added. However, the new address is not being displayed in the subform. If I use the command
22
5039
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 calling up another form or report that uses some of the same data. We came up with a work around that saves the current record's ID, does a
1
2504
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 think--newbie here). Now I need the second subform (subAccount) to update when I add a visit in the subVisits subform. I assume that the AfterUpdate would do it, but I cant figure out what the code is to update another subform would be. Not...
14
11462
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. The command button passes the criteria as a string to a query. A subform, which is based on this query, shows the results of the search.
11
7160
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 mind I am wonder if this is causing my problem, but I don’t want to go through the work to convert to DAO unless I know it is truly in my best interest.) I am having problems getting a requery to show up consistently on a couple of forms. I have...
2
1014
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 record to the table on which the recordset is based. On closing FormB after inputting a new record, I would like to refresh/requery the listing in FormA automatically so that it includes the new record. I don't seem to be able to get this to...
0
8709
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
8638
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
9058
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
8952
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,...
0
7791
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4395
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4649
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2371
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2018
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.