Defining Variables (1 Viewer)

GinaWhipp

AWF VIP
Local time
Today, 10:23
Joined
Jun 21, 2011
Messages
5,900
My bad, I thought those were tabs but I see the tabs now. Hmm, then I am still missing something...

1. I have a main menu form that you can select a number of buildings (eg.1-100).
So you have now selected your Building ID

2. I then click and open a form called bldgform for that building that a have a textbox with name and control source of BldgAbb_ID for bldg1.
Then you open bldgform, I am assuming from the Main Menu, which will show the name of the building.

3. I then click on a button cmdElev on bldgform that opens a report to show all the elevators that match (BldgAbb_ID) bldg1 and have information on it.
From the bldgform I can open the reports which are absed on the Building ID

4. On the same bldgform I have another button cmdAlarms that opens another report that same way with control source and name BldgAbb_ID.
And I can also open additional reports.

Now, the associated image which can be stored in table for the buildings can be loaded via code.

Why do you need so many Forms when it appears everything can be done from the Main Menu and blsgform? Why do you need a Module to declare variables when the Building ID is already available? Just flip the image.
 
Local time
Today, 08:23
Joined
Dec 13, 2019
Messages
79
Why do you need so many Forms when it appears everything can be done from the Main Menu and blsgform? Why do you need a Module to declare variables when the Building ID is already available? Just flip the image.

Because transparent buttons go over images of pumps (etc.) you click on the pump it opens a form with info on it. Each transparent button goes to a specific record for a piece of equip in this common form for each building.

example to make it clearer
I try to make it simple......
Imagine a picture of a building with windows in a form...
Each window of the building has a transparent command button....
If you click on the window it brings up another form with who works in the office...
But you have many buildings each building completely shaped different.....
Some with hardly any windows and different people working in the offices....
So the command buttons could not be copied over as each building is completely different....


Thanks for your time
 

GinaWhipp

AWF VIP
Local time
Today, 10:23
Joined
Jun 21, 2011
Messages
5,900
Ah, I'm now seeing the *bigger* picture. So in creating a Module you are hoping to use one line to call the code for the buttons? Because no matter what each button is going to need something. Nope, let me restate that... you could just use an Embedded Macro for each button and then the code goes where the button goes. This assuming the are all using a PK of the same name (which sounds like they are).

I mean no matter what you are going to need quite a few Forms with buttons in different places.
 

Micron

AWF VIP
Local time
Today, 10:23
Joined
Oct 20, 2018
Messages
3,478
I mean no matter what you are going to need quite a few Forms with buttons in different places.
Maybe, but it would be interesting to experiment with a test db. I was thinking that if there weren't too many properties one could set it up as a table for each property and one that holds all forms data, assuming only command buttons need to be controlled, or just take a chance and create a flat table. If the max number of buttons for any pic required 10 buttons for example, then maybe it would look like this:

table1.jpg


I have done something similar but less complicated: All buttons were stacked in one location in design. Depending on which ones needed to be visible, those were moved into position using the topmost value + button height + spacing. Result was that if userA could see buttons 1, 2 and 5 and userB could see 3, 5 and 7 each set of 3 appeared in the same place rather than making some disabled (showing disabled features they might be curious about) or gaps because some were invisible.

I'm not convinced it's not doable yet, but I respect that the notion perhaps doesn't answer what's being asked for and I'm going to have to let this one go for now. My left ring finger is really starting to hurt when I type. Hint: wear gloves when pruning stuff you're holding in your hand, or at least keep your dang fingers out of the pruning shears.
 
Local time
Today, 08:23
Joined
Dec 13, 2019
Messages
79
So any ideas of how the code would look to do this in a module? Passing BldgAbb_ID from a form to a report?

How would I define the variables for this code? The BldgAbb_ID is text so I would set it to string but where would I go form here? I am opening a report based on the building abbreviation of a form. Thanks in advance for your help.
Code:
Option Compare Database
Option Explicit
Dim BldgAbb_ID As String

Private Sub cmdElev_Click()
On Error GoTo cmdElev_Click_Err

    DoCmd.OpenReport "rptElevators", acViewReport, "", "[BldgAbb_ID]=" & "'" & BldgAbb_ID & "'", acNormal

cmdElev_Click_Exit:
    Exit Sub

cmdElev_Click_Err:
    MsgBox Error$
    Resume cmdElev_Click_Exit

End Sub
 

Gasman

Enthusiastic Amateur
Local time
Today, 15:23
Joined
Sep 21, 2011
Messages
14,238
Is the key for the report always the same?
Set a TempVar from the form BldgAbb_ID or pass it it in to the sub
Establish a naming convention.
So cmdElevator opens report rptElevator
Then you can either pass in the control name or again use a TempVar

In the Public Sub you would have something along the lines of

Code:
DoCmd.OpenReport "rpt"& Mid(ctrName,3), acViewReport, "", "[BldgAbb_ID]='" & BldgAbb_ID & "'"
Either way you have to tell the sub the arguments you want to use.?
 

onur_can

Active member
Local time
Today, 07:23
Joined
Oct 4, 2015
Messages
180
Create a module so that you can use the variable in all forms and define a global variable inside this module. You can set the value of this variable no matter which form you go, you get a value in all forms and even in all reports.
Code:
Global ReportVariableID As Integer
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 15:23
Joined
Jul 9, 2003
Messages
16,274
How about:-
Open a Report From Module

SAMPLE File OpenRptFromModule_1a.zip MOVED:-

It's on a Digital downloads website HERE:- https://gum.co/SameRptManyForms

Available for Free for a limited time, use Coupon Code:- v0epdg7
 
Last edited:

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 15:23
Joined
Jul 9, 2003
Messages
16,274
Tony, I don't see how that takes into account which particular button has being pressed?

Good Point Paul...

It meets the requirement as I understand it. However, there is indeed room for improvement.

A sample dB from the OP would go along way in answering everyone's questions.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 15:23
Joined
Jul 9, 2003
Messages
16,274
In this example I demonstrate how you can send information from the calling form into the report, giving the report a unique header based on the form it was called from.

It's on a Digital downloads website HERE:- https://gum.co/SameRptManyForms

For a Free Copy Contact ME!
 
Last edited:
Local time
Today, 08:23
Joined
Dec 13, 2019
Messages
79
Code:
conAppName = "(Replace this Local Variable with a Global One) "
So what should I do here? I modified your database below based on what I would need. Do you see any problems with what I did?
Thanks again this was awesome that you posted this db thanks!
 

Attachments

  • ModifiedOpenRpt.accdb
    628 KB · Views: 104

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 15:23
Joined
Jul 9, 2003
Messages
16,274
So what should I do here?

Place This at the top of a Stand alone Module (NOT IN a FORM Module)

Code:
Option Compare Database
Option Explicit

Public Const conAppName As String = "Your Application Name"

But before you do that I did another example that you might find more useful. You can download it here: --- https://gum.co/SameRptManyForms --- For a FREE Copy, Contact me...

This NEW example demonstrates how you can pass the "Calling Form" name into the Report. You can give your Report a useful heading which relates to the Form it was called from.
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Today, 10:23
Joined
Feb 19, 2002
Messages
43,233
You can write a function that takes arguments. You could use a single function or a different one for each report.

However, there are far better ways to do this than to create a separate form for each piece of equipment. You could have used the picture to show based on the part selected. Then you'd have one form instead of hundreds. Rather than modifying the hundreds of forms to make the change to call standard functions, you should probably fix the underlying problem that caused you to think you needed hundreds of forms to begin with.
 
Local time
Today, 08:23
Joined
Dec 13, 2019
Messages
79
You can write a function that takes arguments. You could use a single function or a different one for each report.

However, there are far better ways to do this than to create a separate form for each piece of equipment. You could have used the picture to show based on the part selected. Then you'd have one form instead of hundreds. Rather than modifying the hundreds of forms to make the change to call standard functions, you should probably fix the underlying problem that caused you to think you needed hundreds of forms to begin with.
Basically one form for all the equipment. Problem is linking form multiple command buttons.
example to make it clearer
I try to make it simple......
Imagine a picture of a building with windows in a form...
Each window of the building has a transparent command button....
If you click on the window it brings up another form with who works in the office...
But you have many buildings each building completely shaped different.....
Some with hardly any windows and different people working in the offices....
So the command buttons could not be copied over as each building is completely different....
.
The form with all the people that work in the office is the same..Above is just a example of how it works.
 

Micron

AWF VIP
Local time
Today, 10:23
Joined
Oct 20, 2018
Messages
3,478
You would probably pass the button name or its tag property value to the function so that anything that needs to be opened or referenced can be known by that reference.
FYI I feel like it might be perceived that I started something and then backed off wrt helping to implement it. The last week or so has been kinda nuts around here so my ability to follow through has been impacted. Sorry.
 
Local time
Today, 08:23
Joined
Dec 13, 2019
Messages
79
Don't worry about it everyone has been awesome to share their knowledge and time...
All the help over the past few months has helped me so much!!
 

Users who are viewing this thread

Top Bottom