Autoexec and command line parameters

Lateral

Registered User.
Local time
Today, 13:34
Joined
Aug 28, 2013
Messages
388
Hi guys (newbie)

Sorry for the vague title.

I am using Access 2007 and have a split design (BE and FE).

Everything is running well.

I have set up an Autoexec file that contains about 15 different "things" such as Runcode and OpenQuery's. Again this is all working fine.

Currently, the application is working on a standalone PC (PC1) and I need to have it working on another PC (PC2) sharing a common back-end....again I have this working as well.

The issue is that I PC1 to run everything in the Autoexec but I only want PC2 to run a few of the actions......I'm thinking that the best way would be to somehow parameterise the Autoexec so that I just need to specify something on the command line of the shortcut that starts the application on PC2 so that some of the actions are not run....

Unfortunately, this is a bit above my level of expertise hence my request for help.

Thanks guys.

Regards
Greg
 
You have a bunch of options in front of you. Here are a couple that immediately sprang to mind.

1. Each PC should have a separate copy of the FE, therefore each FE has its own Autoexec macro. Modify the two separate versions such that they each perform the separate tasks required.

2. Run your procedures dependent upon a a stored variable. For example, if some of those procedures should only occur once per day, store the date that they were last run, and check against that date each time the application is opened. Or if your users are logging into the system; tie the running of those procedures to a specific user or user level.
 
I don't see a way to pass a command line parameter to the autoexec, but you could just tailor macros for each PC in place of the autoexec and then invoke them in your shortcut with /x macro. See

https://support.microsoft.com/en-us/kb/209207

for more about this.
 
I would use an ini file, or something similar.

include options in there appropriate for each user.
 
You can write code that targets each machine, like . . .
Code:
Sub Startup
   Select Case Environ("ComputerName")
      Case "Shipping-PC"
         MsgBox "Run this code for the machine in shipping"
      Case "Accounting-PC"
         MsgBox "Run this code for some other machine"
      Case Else
         MsgBox "This is an unknown machine"
   End Select
End Sub
And you can call this Startup method using RunCode in AutoExec
 
Hi guys

Thanks for the prompt replies and good ideas!

I though about having 2 versions of the FE but that can cause other issues relating to keeping the 2 versions the same but it still may be a good interim fix.

Markk, as I am a newbie, can you please explain your idea some more? Are you saying to take all of the currently individual macros etc and call them from a piece of VBA code and use the DoCmd.RunMacro?? and to use the Autoexec to action the new bit of VBA code?

Regards
Greg
 
Are you saying to take all of the currently individual macros etc and call them from a piece of VBA code and use the DoCmd.RunMacro?? and to use the Autoexec to action the new bit of VBA code?
Yes. Exactly. And use Environ("ComputerName") to determine which machine is running the code, and decide, based on that, how to proceed.
 
Thanks Mark,

I'll give it a try and report back.

Regards
Greg
 
another useful setting if you using Mark's idea is environ("username")

There are about 40 different environ settings, although most will not be useful for this particular issue.

one issue with "hard-coding" things is that you may need to keep rebuilding the database every time you have a new user.
 
Hi guyss

Ok, here is the update....I got it all working!

This is what I did (I hope I use the correct terminology):

1. I created a new function and moved the execution of a number of the macros that were being run in the Autoexec to this new function and created a series of "DoCmd.OpenQuery" statement to run them.

2. I figured out how to get my hands on the "USERDOMAIN" system variable instead of the "USER" variable as its possible that the 2 PC's that will be running the FE will have the same USER name.

3. I created a new field in one of the tables that is used to contain various configuration setting called "UserDomain" that will be used to store the UserDomain of the PC that is to run the "DoCmd.OpenQuery" statements. If the Userdomain of the PC runnning the FE does not mach what is set in the "UserDomain" setting, then the "DoCmd.OpenQuery" statement are bypassed.

I have tested this and it works really well....I'll do a bit of tidying up and that's about it!

Thanks again for helping me and pointing me in the right direction...

Regards
Greg

3. I put the "DoCmd.OpenQuery" statements in an "If Else" loop based upon "Web_Parts_Append_New_Records"
 

Users who are viewing this thread

Back
Top Bottom