Hi,
I'm trying to write code for a form when it closes. It's supposed to requery a combo box depending on which form is currenlty open in the background behind the current form, shown below:
Private Sub Form_Close()
If Forms(frmProjec Total).CurrentV iew <> 0 Then
Forms![frmProjectsTota l]![cboCity].Requery
Else
Forms![frmProjectsSear ch]![cboCity].Requery
End If
End Sub
If frmProjectsTota l is open behind this form, then it should requery the combo box on that form. If it's not open, that means frmProjectsTota l is open behind this form and should requery the combo box on that form instead. At any given time either only one of frmProjectsTota l or frmProjectsSear ch is open.
This code works for requerying frmProjectsTota l when it's open, but it won't work for requerying frmProjectsSear ch when that's the form that is open. It gives an error message that it can't find frmProjectsTota l. I don't understand it; this is what the code is supposed to do: of course it can't find frmProjectsTota l, that's because in this condition, it's not open.
I think my code might be wrong.
Any suggestions?
Thanks,
Wayne.
10 1976
I find this a pain in the A ... I think you have to back up to the documents collection or something like that to access the form if it's not open (and if it's not, the code will crash as you have found).
Alternatively, you could invoke your own error handling and test against that :
On Error Resume Next
i= Forms(frmProjec Total).CurrentV iew
If Err=0 Then
Forms![frmProjectsTota l]![cboCity].Requery
Else
Forms![frmProjectsSear ch]![cboCity].Requery
End If
On Error Goto 0
(DISCLAIMER: I didn't test this code!)
or maybe you could just call out Forms(2).Name and run your If statement against that?
James
hmmmm still workin at it. I did some error checking with error dialog boxes that pop up telling me which conditition the program entered. No matter which form is open, the program will always enter into the first condition, it never enters the else condition (even when frmProjectsTota l is not open). hmmmmm......... ....
hmmm
any more suggestions?
MMcCarthy 14,534
Recognized Expert Moderator MVP
Pass the form name to a Global variable and then use that to decide which combobox to requery.
Mary
Hi Mary, good to hear from you, as usual,
Since I'm an Access noob, I'm not sure what you meant by pass the form name to a global variable. I read up on this, and apparently global variables are defined in modules that run at startup. So I created a module called WhichForm. Then I defined a string variable called:
Dim WhichForm As String
I'm not sure how my form would call this module.
Wayne.
Pass the form name to a Global variable and then use that to decide which combobox to requery.
Mary
Ok I tried some more stuff... Here is what I came up with so far:
In my module I wrote:
Option Compare Database
Option Explicit
Public Sub WhichForm()
If Forms(frmProjec tsTotal).Curren tView <> 0 Then
Forms![frmProjectsTota l]![cboCity].Requery
Else
Forms![frmProjectsSear ch]![cboCity].Requery
End If
End Sub
Then on the close command of my form I wrote:
Private Sub Form_Close()
Call WhichForm
End Sub
But I get an error when it tries to run the command: Call WhichForm
hmmmmmmm
MMcCarthy 14,534
Recognized Expert Moderator MVP
Hi Mary, good to hear from you, as usual,
Since I'm an Access noob, I'm not sure what you meant by pass the form name to a global variable. I read up on this, and apparently global variables are defined in modules that run at startup. So I created a module called WhichForm. Then I defined a string variable called:
Dim WhichForm As String
I'm not sure how my form would call this module.
Wayne.
Define the variable as
Global WhichForm As String
MMcCarthy 14,534
Recognized Expert Moderator MVP
Forget the code in your last post.
In the form Open event of the two forms 'frmProjecTotal ' and 'frmProjectsSea rch' put the following: - WhichForm = Me.Name ' this will pass the current form name to the global variable.
Now in the Form close event of the other form ... -
Private Sub Form_Close()
-
-
If WhichForm = "frmProjectsTotal" Then
-
Forms![frmProjectsTotal]![cboCity].Requery
-
ElseIf WhichForm = "frmProjectsSearch" Then
-
Forms![frmProjectsSearch]![cboCity].Requery
-
End If
-
-
End Sub
Mary
ADezii 8,834
Recognized Expert Expert
Hi,
I'm trying to write code for a form when it closes. It's supposed to requery a combo box depending on which form is currenlty open in the background behind the current form, shown below:
Private Sub Form_Close()
If Forms(frmProjec Total).CurrentV iew <> 0 Then
Forms![frmProjectsTota l]![cboCity].Requery
Else
Forms![frmProjectsSear ch]![cboCity].Requery
End If
End Sub
If frmProjectsTota l is open behind this form, then it should requery the combo box on that form. If it's not open, that means frmProjectsTota l is open behind this form and should requery the combo box on that form instead. At any given time either only one of frmProjectsTota l or frmProjectsSear ch is open.
This code works for requerying frmProjectsTota l when it's open, but it won't work for requerying frmProjectsSear ch when that's the form that is open. It gives an error message that it can't find frmProjectsTota l. I don't understand it; this is what the code is supposed to do: of course it can't find frmProjectsTota l, that's because in this condition, it's not open.
I think my code might be wrong.
Any suggestions?
Thanks,
Wayne.
The correct, and most efficient, way of handling this situation is to reference the Forms Collection which contains an entry for each Form that is currently 'Open': - Dim frm As Form
-
-
For Each frm in Forms
-
If frm.Name = "frmProjectsTotal" Then
-
Forms![frmProjectsTotal]![cboCity].Requery
-
Else
-
Forms![frmProjectsSearch]![cboCity].Requery
-
End If
-
Next
Thanks guys! :) I got it.
This is the code I ended up using: - Dim frm As Form
-
-
For Each frm In Forms
-
If frm.Name = "frmProjectsTotal" Then
-
Forms![frmProjectsTotal]![cboCity].Requery
-
Else
-
If frm.Name = "frmProjectsSearch" Then
-
Forms![frmProjectsSearch]![cboCity].Requery
-
End If
-
End If
-
Next
I had to use an extra nested if statement for it to work.
This court is adjourned!
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Dale Anderson |
last post by:
I have a schema that I'm trying to read. The schema has an element named
'GrantApplication' and one with a namespace prefix named
'SF424:GrantApplication'. When I try to read this schema in, I get an
exception saying 'A datatable named 'GrantApplication' alread belongs to this
dataset'. Why is dotnet not recognizing the namespace prefix and treating
these like two separate elements?
Thanks for your help.
|
by: Kenneth Courville |
last post by:
Hello, I'm looking for assistance with the Access object model. I know
this is VB, but I'm building an Office Add-using C# directed at Access
2002. I'm literate in VB, so you can reply in VB... I think my problem
mainly lies in knowing the quirks of the Access object model.
Basically, I'm looking for a method of determining if an Access database
is open yet. AND I'm looking for a method that doesn't not require
checking for an...
|
by: Olav.NET |
last post by:
I am a .NET/C++ developer who is supposed to do some work with Access.
I do not know much about it except for the DB part.
Questions:
*1*
I am looking for INTENSIVE books to get quickly up to speed.
I like books with practical exercises, and also with test questions (like
cert books)
*2*
|
by: ammarton |
last post by:
Hello all...I'm a bit new to working with Macros in Access so forgive
me if the terminology I use is not accurate.
To preface this, basically I am using a form on a replicated database
so the end-user can filter on a specific report they want to see. This
database was designed by my predecessor (of which he left no
documentation) and I need to add some additional functions to this
end-user filter report.
Within one Macro, he has over...
|
by: Dave Taylor |
last post by:
I have a VB.NET WinForms project that has about 15 forms in it. When I
opened the project yesterday, one of the form files does not open as a form
(i.e. double-clicking it in Solution Explorer opens up the code file, not
the form designer). Also, it does not appear to recognize the code
file....there are no outlining indicators, typing in the code file there is
no Intellisense stuff, and the code does not compile saying that it doesnt...
| |
by: Deano |
last post by:
Just looking at C Sharp to see if it might be worth my while learning
something new. Has anyone here tried a .NET language and tried to replicate
a existing Access app?
I would be interested to hear how any stories about this and in particular
how one deals with not having subforms - can you get a third-party control
to fill that gap?
|
by: Jordan S. |
last post by:
SQL Server will be used as the back-end database to a non trivial client
application.
In question is the choice of client application:
I need to be able to speak intelligently about when one client (MS Access vs
..NET Windows Forms) would be preferred over the other. While I have some
good arguments on both sides, I would appreciate your points of view on the
topic.
|
by: nayjdk |
last post by:
I have just started converting some AutoCAD (.dwg) files into
Autodesk's version of a pdf file which carries a .dwf file extension. I
use Access
to manage all of my files and have started loading records of each of
these files into my database. Each record has a hyperlink that is
supposed to open
the drawing but when I click on the link nothing happens. I can define
a different hyperlink in the same table using a .dwg or any other file...
|
by: Greg Strong |
last post by:
Hello All,
The short questions are
1 Do you know how to make DSN connection close in Access to Oracle 10g
Express Edition?
&/or
2 Do you know how to make a DSN-less pass-through query work from
|
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...
|
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...
| |
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |