Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HOW DO I USE A BATCH FILE TO AUTO LOG-IN???

Status
Not open for further replies.

jeremyhache

Programmer
Sep 30, 2002
19
0
0
US
I set up a macro to run a report in Access when I'm not around, so it needs to open Access, log in as an Admin, and run the macro, then preferably close Access. I wrote a batch file that tries to run the macro, but I'm unsure as to how to input the username and password automatically and the syntax for doing so. Right now the following batch file opens the database and waits for the password, then when I log in it prompts for overwriting the existing file which I press 'Y' to do:

PATH = "C:\Program Files\Microsoft Office\Office\;C:\Windows\Command"
START /WAIT Msaccess.exe "C:\Inetpub\ /x "AutoEndOfDayQCReport"
EXIT

I know there has to be a way to do this with the SendKeys function but I am not proficient at using it and I do not know the correct syntax! Please help!
 
Jeremy,

START /WAIT Msaccess.exe "C:\Inetpub\ /User UserNameHere /pwd PasswordHere /x "AutoEndOfDayQCReport"

Will get you past the login prompt.

In your macro, SetWarnings to false and you won't have to confirm anything.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.
 
I just tried that and it doesn't work!! It definitely should but it still pauses at the password prompt and waits for me to put a password in. Then when I continue it still prompts me on whether or not to overwrite the existing file. Should I reinstall access?
 
Jeremy,

No. Don't reinstall. Break it down into pieces and we'll get it right.

The User and Pwd switches definitely work. Try just making a one-line batch file that does the whole thing:
"PathAndFileNameForMSAccess.exe" "PathAndFileNameToYourDatabase" /wrkgrp "PathAndFileNameToYourWorkgroup.mdw" /User YourUserName /Pwd YourPassword

Leave the macro out of it for now, so you're only trying to tackle one thing at a time.

Here's an example of one I just made:
"C:\Program Files\Microsoft Office\Office\msaccess.exe" "C:\bnkrecsw\Develop\Tools\BnkRecFE.mdb" /wrkgrp "G:\home\BankRec\BnkRecSW\Prdction\Tools\BnkRec.mdw" /User Jeremy /Pwd 111111

Let us know what happens when you try a one-liner like that.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.
 
Alright, I got logging in automatically to work when I broke it down and figured out where my mistake was. Thanks. However, Access now opens and goes straight to a warning box asking if I want to replace the existing file since my macro copies a report to a file on my intranet directory, so I want it to copy over itself. In the Macro Design View, all I have for Actions are the OutputTo Action which says where to copy it to and in what format, and then the SetWarnings where I have No in the Warnings On property listed below. Shouldn't this work?? I already tried moving the SetWarnings Action to the first spot in the Actions column, then the OutputTo below it, just in case that had something to do with it. Thanks in advance for helping me.
 
Well, you would definitely need it before the outputTo for it to do you any good.

I'm not really much good with Macros, as I was told by many serious developers to avoid them and just suffer the pain of learning vba. It's what I suggest to all people learning Access.

If you want to convert your macro to code and post the code here, we'll be able to get this part going as well.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.
 
Ok, here's the converted code:


PATH = "C:\Program Files\Microsoft Office\Office\;C:\Windows\Command"
START Msaccess.exe "C:\Inetpub\ /User "Admin" /pwd "Admin" /x "AutoEndOfDayQCReport"
EXIT
Option Compare Database

'------------------------------------------------------------
' AutoEndOfDayQCReport
'
'------------------------------------------------------------
Function AutoEndOfDayQCReport()
On Error GoTo AutoEndOfDayQCReport_Err

DoCmd.SetWarnings False
DoCmd.OutputTo acReport, "End of Day Report QC Yesterday", "SnapshotFormat(*.snp)", "c:\Inetpub\ False, ""


AutoEndOfDayQCReport_Exit:
Exit Function

AutoEndOfDayQCReport_Err:
MsgBox Error$
Resume AutoEndOfDayQCReport_Exit

End Function
 
It works the same in a macro as in code:

SetWarnings to "No"
Output report
setwarnings to "Yes"


or

(second & third lines should be all one line)

DoCmd.SetWarnings False
DoCmd.OutputTo acOutputReport, "Your ReportName", acFormatRTF, "Your File Name"
DoCmd.SetWarnings True
 
What exactly is the warning message?

Have you looked at other methods of saving this? If you know you're going to be OK with blowing away the other file, you could check to see if it's there, and if it is just delete it.

Then there would be no warning message to worry about.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.
 
Alright, that's an awesome idea, in fact I just added a line to the batch file that deletes the old file before I run the Macro. So that's all set! But now is it possible to close Access either through the batch file or the macro, or does it have to stay open until somebody manually closes it??
 
Thanks so much! I figured out the last request I had. There's a quit Action that you can choose in the macro design that exits Access so now my batch file and macro are complete! Thank you so much! You've been most helpful! Plus you've got an awesome name to match!

Jeremy Hache
 
Glad I could help. Power to the Jeremys. =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top