|
-
Sep 9th, 2005, 08:04 AM
#1
Thread Starter
New Member
Office VBA automation
Hi everyone,
I'm trying to make a MS Access add-in using VB.NET, the solution will be
used for a maternal care company. The add-in works fine, however now the
VB.NET add-in needs to call VBA code in the MS Access database and also
pass parameters (i.e. can't use macros).
Does anyone know if it's possible to do this? If so, how?
As an example I would like to do the following:
VB.NET add-in sample code:
VB Code:
Dim mappAccess As Microsoft.Office.Interop.Access.Application
Dim OrderArgs As String
Const strConPathToSamples = "C:\Documents and Settings\Anders\" _
& "My Documents\"
strDB = strConPathToSamples & "MyAccessDatabase.mdb"
[COLOR=Lime] ' Gets current instance of MyAccessDatabase.[/COLOR]
mappAccess = _
GetObject(strDB).Application
[COLOR=Lime] 'Open a form[/COLOR]
OrderArgs=<something>
mappAccess.DoCmd.OpenForm("Orders", , , , , , OrderArgs)
[COLOR=Lime] 'Run a macro[/COLOR]
mappAccess.DoCmd.RunMacro("Order_macro")
[B]'Can you call a VBA sub-procedure located in a Class module or a standard module, and if so how?[/B]
Dim OrderNr as String = "A0001"
Dim OrderStatus as Integer = 0
mappAccess.<what should be written here?> ("UpdateOrder", OrderNr, OrderStatus)
Sample MS Access VBA code from MyAccessDatabase.mdb, inside standard module "Module1":
VB Code:
'This function is located in a MyAccessDatabase class module or standard
'VBA module and should be called by MyAccessAddin.dll:
Public Function UpdateOrder(OrdNr As String, OrdStatus As Integer) As Integer
'Do what you gotta do
'Return
UpdateOrder = 0
End Function
I have been unable to find any information about this. Does anyone know
anything about this?
Thanks for any help,
Anders, programmer
-
Sep 9th, 2005, 08:57 AM
#2
Re: Office VBA automation
It may be easier to just write the fuinction in .net instead of running it inside of Access. Not to mention that this way your code will be centralized in your .net project.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 9th, 2005, 03:09 PM
#3
Thread Starter
New Member
Re: Office VBA automation
Well, thanks for the help, why didn't I think about that!!
Excuse me for the irony *no harm ment , but my example naturally assumes that the call from the add-in back into MS Access is needed, and that a macro isn't sufficient since it won't allow passing any parameters (or least I think so).
I guess the answer is that one has to use some ugly solution with dummy forms using openargs as parameters, together with the DoCmd.Openform method.
Cheers,
Anders
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|