FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Samples/UsingDAO/MyAddIn.vb at master · Excel-DNA/Samples · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
Excel-DNA
/
Samples
Public
Notifications
You must be signed in to change notification settings
Fork
83
Star
134
Code
Issues
12
Pull requests
1
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
Samples
/
UsingDAO
/
MyAddIn.vb
Copy path
More file actions
More file actions
Latest commit
History
History
History
51 lines (42 loc) · 1.87 KB
Breadcrumbs
Samples
/
UsingDAO
/
MyAddIn.vb
Copy path
File metadata and controls
51 lines (42 loc) · 1.87 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Import
s
System.I
O
Imports
Microsoft.Office.Interop.Access.Dao
Imports
ExcelDna.Integration
Public
Module
MyAddIn
' This would not be needed in VBA - in .NET we must instantiate the root COM object
Private
MyDBEngine
As
New
DBEngine()
Private
MyDatabase
As
Database
Const
MyDatabasePath
As
String
=
"TestDB.mdb"
Private
Sub
EnsureDatabaseIsConnected()
If
MyDatabase
Is
Nothing
Then
' We've not set the database yet - try to open or create a new one
If
File.Exists(MyDatabasePath)
Then
MyDatabase
=
MyDBEngine.OpenDatabase(MyDatabasePath)
Else
' Create new DB for testing - this could be OpenDatabase too
MyDatabase
=
MyDBEngine.CreateDatabase(MyDatabasePath,
Locale:=LanguageConstants.dbLangGeneral)
' Add the tables or give an error ....
' ...
End
If
End
If
End
Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' These will be UDF functions you can call from a sheet...
' Check that the DAO is working correctly
<ExcelFunction(Description:=
"Returns the version of the loaded DAO DBEngine"
)>
Public
Function
DBEngineVersion()
As
Object
Return
MyDBEngine.Version
End
Function
' Check that the database was opened
<ExcelFunction(Description:=
"Returns the name of the open database"
)>
Public
Function
DatabaseName()
As
String
EnsureDatabaseIsConnected()
Return
MyDatabase.Name
End
Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' This will be a macro added to the Add-Ins tab on the ribbon
<ExcelCommand(MenuName:=
"Excel-DNA DAO Sample"
,
MenuText:=
"Show Database Name"
)>
Public
Sub
ShowDatabaseName()
EnsureDatabaseIsConnected()
MsgBox(MyDatabase.Name,
Title:=
"DAO Sample"
)
End
Sub
End
Module
Back
|
FazBrowse Home
|
New Git URL