Defining Variables (1 Viewer)

GinaWhipp

AWF VIP
Local time
Today, 16:10
Joined
Jun 21, 2011
Messages
5,899
You can what @Isaac suggested but if it's on the Form not sure why you need to declare it. It should only pull for the referenced control. So, once you select the Building you can just pick any report you want to print, the code does not care that you are clicking a different command button.
 
Local time
Today, 14:10
Joined
Dec 13, 2019
Messages
79
You can what @Isaac suggested but if it's on the Form not sure why you need to declare it. It should only pull for the referenced control. So, once you select the Building you can just pick any report you want to print, the code does not care that you are clicking a different command button.
Not working didn't think this would be so difficult thanks for all the help.
 

Gasman

Enthusiastic Amateur
Local time
Today, 21:10
Joined
Sep 21, 2011
Messages
14,265
Not working didn't think this would be so difficult thanks for all the help.
Well I'd say it is not. It is difficult however determining exactly what you are trying to do, only getting bits of info here and there.

Now you have elaborated on how you are working, you can create a public sub/function in a module. you just need to pass in any data it needs to determine
1. What report to run
2. What criteria to run

However, from what you are saying that is all you need, so a module is a little overkill I would have thought?
If you were exporting to Excel, creating a PDF and emailing the report all at the same time, then a public sub/function would be ideal.

Eg. You add yet another button to print another report, you need to find out what your function/sub is called, then call it with the two respective parameters. Hardly less work than writing a DoCmd.OpenReport?

Up to you though.
 
Last edited:
Local time
Today, 14:10
Joined
Dec 13, 2019
Messages
79
So hopefully this makes sense..
- I would like to use a module because I can't use one form for multiple buildings because each one is different. (Reason...Overlay of command buttons on different mech. pictures for each building)
- Each form has 7 command buttons that are exactly the same that open reports etc.
- If I need to change one of these 7 buttons on 100+ probably 300+ forms because my boss wants something added I trying to think ahead.
Below is an example of one command button on one of the bldg. forms that on click you go to the module (mdlCommon.cmdElevators_Click) .
The only problem is when I click on the command button it says I have to define variables and highlights BldgAbb_ID. Can someone please help me with the code.

Code:
mdlCommon.cmdElevators_Click
Code:
Option Compare Database
Option Explicit


Public Sub cmdElevators_Click()
On Error GoTo cmdElevators_Click_Err


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

cmdElevators_Click_Exit:
    Exit Sub

cmdElevators_Click_Err:
    MsgBox Error$
    Resume cmdElevators_Click_Exit

End Sub
 

Micron

AWF VIP
Local time
Today, 16:10
Joined
Oct 20, 2018
Messages
3,478
Almost always when somebody says "I can't because..." they are incorrect because they just don't know any better. If you can think that there must be a way to do something like this with one form, then I can practically guarantee that it can be done. If you add one aspect that applies to all or a majority of cases, you are looking at modifying 300 forms. That is just nuts.

Maybe what you need is a table with all the form controls situations as TF values and the fields as control names. You get the property values from the table and loop through the records that apply only to that form. That's just a high level idea not tailored to your specific situation but that's the gist of if.
 

GinaWhipp

AWF VIP
Local time
Today, 16:10
Joined
Jun 21, 2011
Messages
5,899
So, here's me trying to figure out what you are saying here...
Overlay of command buttons on different mech. pictures for each building)

Are you just changing the background picture but the buttons stay the same? No need for different Forms. Just apply what Micron made reference to, have a table that stores the path to the image and when you look up the Building you can set the background property. Then all you need is one Form. (No way anyone would make a different Form for each building. At least not me.)
 
Local time
Today, 14:10
Joined
Dec 13, 2019
Messages
79
It is nuts I agree. I could bring in the picture from a table but overlay of command buttons in a specific location over a picture how could it be done? The command buttons are in different locations on each form as each diagram of equip. is different. If you could figure that out I would say you are a genius.
 

Micron

AWF VIP
Local time
Today, 16:10
Joined
Oct 20, 2018
Messages
3,478
but overlay of command buttons in a specific location over a picture how could it be done?
top and left coordinates in the table as fields (attributes) of the control.
Absolutely not a genius.
How about the code for the 7 command buttons anyone have any ideas.
Maybe one function that takes the name of the control (button?) as at least one parameter. Right now I personally have little clue as to what you need, but I would bet money that the number of forms needed would be as little as one per group/style at most.

You might want to start a new thread with a very detailed explanation of what is needed without using your design brain.
 

GinaWhipp

AWF VIP
Local time
Today, 16:10
Joined
Jun 21, 2011
Messages
5,899
And a screen shot (or maybe a couple) might help because no way there is not an easier quicker way to get this done.
 
Local time
Today, 14:10
Joined
Dec 13, 2019
Messages
79
-Basically I have 300+ pictures of mechanical drawings each for a different system, multiple buildings.
-Command buttons on the mech. drawing are about 1-50 command buttoms.
-All command buttons when selected go to a common form that brings up information on that piece of equip. including pictures, size, voltage, etc.
-Also on each form with the mech. drawing I have a tabbed control to bring up a live version of current values for the mechanical drawing, email, system for entering maintenance requests on the web, etc.
-The first tab has a copied picture of the live version of the mechanical drawing with all the command buttons
.
So to make a long story short the command buttons would have to be mapped out basically for each picture and stored somewhere to use a common form. I think this would be much harder then using multiple forms. So my question remains how to set up a module to make my life a little easier with some of the common command buttons on each form.
 
Local time
Today, 14:10
Joined
Dec 13, 2019
Messages
79
Screen Shot. FYI the live web version can't be altered to accommodate what I need as it is out of my hands.
 

Attachments

  • Example1.JPG
    Example1.JPG
    65.6 KB · Views: 108
Last edited:

GinaWhipp

AWF VIP
Local time
Today, 16:10
Joined
Jun 21, 2011
Messages
5,899
Hmm, I would store image, location of command button in a table but okay.

What could be common? The placement? The image?

And now I'm not getting what the Module would be used for? If you are just *moving* the command button the code goes with it since it's on the one Form. If it's on a different Form then copying the initial Form and moving the button still has the code.
 
Local time
Today, 14:10
Joined
Dec 13, 2019
Messages
79
The module would be if I ever wanted to change anything with the common command buttons at the top. This would save me having to go to each command button on each of the 300+ forms if I needed to adjust something. If I was to store the location of the command button on the drawing in the table how would that work (example)? The picture is very easy but how about the command buttons? The command buttons on the mech. drawing would not be copied over they would be deleted and redone going to different records and placed in different areas.
 
Last edited:
Local time
Today, 14:10
Joined
Dec 13, 2019
Messages
79
Could be anything just wouldn't want to change all forms. If you have a solution for using one form I'm all ears but I need help with the code as I wouldn't know how to make it all work. So one form or back to the original question how to define the variables so the module would work. Thanks for the help.
 

GinaWhipp

AWF VIP
Local time
Today, 16:10
Joined
Jun 21, 2011
Messages
5,899
Nothing is coming to mind right off the bat. Especially because ANYTHING could change. Is there anything that remains the same? I mean writing a Module to change anything would be just as bad as changing all the Forms individually.
 
Local time
Today, 14:10
Joined
Dec 13, 2019
Messages
79
Like I said before the Command buttons code at the top would remain the same for all 300+ forms. If I needed to change it on one module it would change it for all of them making this easy to change if needed in the future. The 7 command buttons code on top of the form stay the same opening a report or form.
 
Local time
Today, 14:10
Joined
Dec 13, 2019
Messages
79
So the 7 command buttons code on top of the form stay the same for every form. See screen shot.
 

Users who are viewing this thread

Top Bottom