access macro.

Hi.
I have a file that will always be located in a folder location called:
C:\Pictures\OSSMTP.dll

When some on on first use installs a database i require this dll file to be copied and pasted into the C:\Windows\System32    'Folder'
Then i need to install the dll file by entering      regsvr32 OSSMTP.dll        

I need this to be done by a makro so i can create a button on a form that does this action..

Im not sure how.
andybrookeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JezWaltersCommented:
Assuming your users have the relevant permissions, you should be able to achieve what you're after using the FileCopy and Shell statements.
andybrookeAuthor Commented:
sorry i have never used a makro before. how would i do what you suggest?
JezWaltersCommented:
Just to clarify, I mean like this:
Public Sub YourButton_Click()
    FileCopy "C:\Pictures\OSSMTP.dll", "C:\Windows\System32\OSSMTP.dll"
    Shell "regsvr32 C:\Windows\System32\OSSMTP.dll", vbHide
End Sub

Open in new window

Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Sarika30Commented:
for copying files:
FileCopy "C:\Users\SourceFolder\Test.dll", "C:\Users\DestFolder\Test.dll"

not sure how to register dll's.
try creating a batch file.
carsRSTCommented:
This code should do it.  


Set WshShell = CreateObject("WScript.Shell")
WshShell.Run ("regsvr32 /s OSSMTP.dll")

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JezWaltersCommented:
Right-click on the button on your form and then select Properties to display the Property Sheet.  Next, click on the "On Click" property value, select "[Event Procedure]" from the drop-down combo box and then click the elipsis ("...") button.
When the Microsoft Visual Basic editor opens, copy the two statements above into the procedure that Access has automatically created for you.  Bingo!  :-)
carsRSTCommented:
In design mode on your form, add your button.  Then hit Cancel on the command button wizard.  Right click the button and select "Code Builder"

Then just make your code look like this below....

Private Sub Command1_Click()
   Set WshShell = CreateObject("WScript.Shell")
   WshShell.Run ("regsvr32 /s OSSMTP.dll")
End Sub

andybrookeAuthor Commented:
Hi. I have used that code and it works great. one small issue if you press the button again after you have used it it comes up with an error box. Runtime error 70 'Permision denied'
Can i get this to stop?
For example could i create a 'IF' formula that 1st looks up the system32 folder to see if file exists, if not then run that code. if it does exist then exit sub?
carsRSTCommented:
This will do same thing.  It will prevent the error from pop

Private Sub Command1_Click()

   If Dir("C:\Windows\System32\OSSMTP.dll") <> "" Then
      Set WshShell = CreateObject("WScript.Shell")
      WshShell.Run ("regsvr32 /s OSSMTP.dll")
   end if

End Sub
carsRSTCommented:
Sorry think i had that logic backwards.
See adjusted code
Private Sub Command1_Click()

  on error goto errH
   If Dir("C:\Windows\System32\OSSMTP.dll") = "" Then 
      Set WshShell = CreateObject("WScript.Shell")
      WshShell.Run ("regsvr32 /s OSSMTP.dll")
   end if
exit sub
errH:
    Msgbox err.description
End Sub

Open in new window

andybrookeAuthor Commented:
Hi. I have ran that last code and it errored however by mixing the IF formula up with the original code it worked fine.
then code i used was:

Private Sub Command0_Click()

On Error GoTo errH
   If Dir("C:\Windows\System32\OSSMTP.dll") = "" Then

FileCopy "C:\Pictures\OSSMTP.dll", "C:\Windows\System32\OSSMTP.dll"
Shell "regsvr32 C:\Windows\System32\OSSMTP.dll", vbHide

End If
Exit Sub
errH:
    MsgBox Err.Description
End Sub

Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.