Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Run A Function of Sub on MS Access
#1
Question 
I designed a small program to use in HR using MS Access 2016.
I am trying to run a function, which I wrote in one of the program modules.
The said function return a string, which shows the folder path for active employee window.

[Image: employee_Folder_Path.jpg]

So, when the program is on, I want to retrieve the employee folder path from the function "EmployeeFolderPath"

may be the code will look something like this.

Code:
Copy      Help
str sPath
Access.Application acApp
;;acApp = I should get the running instance of the program
;; the program path ""\\HR-PC\HR.accdb"
sPath = acApp.Run("EmployeeFolderPath")


Appreciate your kind help


Attached Files Image(s)
   
#2
try something like this 
if not should get you started in the right direction

Function GetMsAccessPath 
Code:
Copy      Help
;/exe 1

typelib Access {4AFFC9A0-5F99-101B-AF4E-00AA003F0F07} 9.0

str sPath
Access.Application acApp
acApp._getactive
sPath = acApp.Run("EmployeeFolderPath")
out sPath
;BEGIN PROJECT
;flags  6
;END PROJECT
maybe this topic will help more
http://www.quickmacros.com/forum/showthr...oft+Access
sorry cannot help more was just trying to get you started in right direction
also search forum for Microsoft Access there are other topics that may help.
in code editor type acApp then .  and you will see a list of functions you can do
   
#3
Well, thank you very much Mr. Kevin. appreciate your help.

Actually, the code did not work. it keeps telling me that the process in not running, but the program is running as you can see from the attached image.
 
is it going to make any difference that I am running the .accde copy of the program.
as you can the from the image the calss name in OMain Huh .

Regards


Attached Files Image(s)
   
#4
The ;/exe 1 is important. It means "run in separate process as User". If don't want separate process, let QM run as User. Set it in Options.
#5
thank you Gintaras for your reply.
I am now receiving an error message that the function is not exist. but it is there, as you can see from the image.


Attached Files Image(s)
   
#6
Don't know, I never use it, I guess maybe the function must be in some other module, or need path like CommandBars.FunctionName.
#7
the reason your getting the cannot find the procedure 'EmployeeFolderPath().'. error  message is because

Your  calling the function incorrectly 

change code to and will work
Code:
Copy      Help
sPath = acApp.Run("EmployeeFolderPath")
and it will work
full code below
Code:
Copy      Help
;/exe 1
typelib Access {4AFFC9A0-5F99-101B-AF4E-00AA003F0F07} 9.0
str sPath
Access.Application acApp
acApp._getactive
;acApp._getfile("C:\Users\kevin\Documents\Database1.accdb")
sPath = acApp.Run("EmployeeFolderPath")
out sPath
;BEGIN PROJECT
;;flags  6
;END PROJECT
 
Tip

Q. How to post QM code to the forum?

A. In QM, to copy all or selected text, use menu Edit -> Other Formats -> Copy for QM Forum. It copies correct and colored code to the clipboard. Then simply paste in the forum. Don't use the Code button.
read more here
http://www.quickmacros.com/forum/showthread.php?tid=786
#8
_getactive and _getfile normally work without problems.

I am using _getfile because if there is more then one file open _getfile gets the correct one.

I was surpriesed that although Access delivers a BSTR the Function works.


Forum Jump:


Users browsing this thread: 1 Guest(s)