New to ArcMap VBA

11810
31
02-08-2016 11:55 AM
EthanDunker
New Contributor II

Hello,

I am new to ArcMap VBA coding and was wondering if there is any good websites to help me understand what I am doing wrong. I have a basic knowledge of VBA for coding in access.

thanks in advance

0 Kudos
31 Replies
JoeBorgione
MVP Emeritus

I can't answer that either but I bet one of these guys will chime in :

Darren Wiens

Xander Bakker

[edit] take a look here too:  Another GIS Blog: Using pyODBC to Connect To Access with ArcPy

That should just about do it....
DanPatterson_Retired
MVP Emeritus

Skip access, export to csv format, then anything can read it.

As you move forward from the python 2.7 etc to python 3.4 and ArcGIS PRO and ... dare I suggest ... maybe even 10.4, you have access to Pandas and Numpy

Importing Access files

or just bring it into Arc* for use there.

EthanDunker
New Contributor II

Here's what I am looking for with access. I have created a database of all of my company's work orders and their location in the county. So currently I am trying to create a tool that when you click on that location on the map. it opens access to that location in the form that has been created. Is this possible with Python? If so I am more then willing to attempt to learn that. As I do prefer to use the most current things. 

0 Kudos
DanPatterson_Retired
MVP Emeritus

If you migrate your database into ArcMap, then it could be as simple as using the Info button or as complex as you like.. either through Arcpy functions and/or python.  I just don't know what level of experience you have with ArcMap and I am not sure if you want to migrate your data into a new form

0 Kudos
EthanDunker
New Contributor II

I don't have much experience at all with ArcMap. I just started working with it 2 weeks ago. About all I can do it link a access table and have it display different symbols based on different values.

0 Kudos
MarkBryant
New Contributor III

I would use the win32com api to communicate with access via python. This way you can open the existing form.

Please note that win32com is no longer installed by default with the newer versions of ArcGIS

I have included a snippet of code below to help

import win32com.client

# Create the Access object
app=win32com.client.Dispatch("Access.Application")

accessDB = r'path to the mdb here'
try:
    # Make Application Visible
    app.Visible=1     
    app.OpenCurrentDatabase(accessDB)

    # https://msdn.microsoft.com/EN-US/library/office/ff820845.aspx
    app.DoCmd.OpenForm(FormName, View, FilterName, WhereCondition, DataMode, WindowMode, OpenArgs)  
    
    # https://msdn.microsoft.com/EN-US/library/office/ff192676.aspx
    #app.DoCmd.OpenReport(ReportName, View, FilterName, WhereCondition, WindowMode, OpenArgs)

    # https://msdn.microsoft.com/en-us/library/office/ff192075.aspx
    #app.DoCmd.RunMacro(MacroName)


except:
    # Add your error handler
    pass

# run these statements no matter where the program goes
finally:
    if app:
        app.CloseCurrentDatabase
        app.Quit()
        del app
Mark.
JamesCrandall
MVP Frequent Contributor

Just move entirely into a File Geodatabase and model your existing Access tables there, relate them to any Feature Classes, set domains/subtypes, editor tracking and be done with it.  You will be opening up your implementation into a whole new world and have capabilities you likely don't even know about (like easily publishing to the web, collector, Web AppBuilder, StoryMaps, and on and on...).

VBA is a dead-end street that has a bunch of foreclosed properties down it.

AndrewQuee
Occasional Contributor III

It's worthwhile noting that Esri has been warning users to switch over and threatening to get rid of VBA for many years, since 10.0, and you are developing in what is essentially an unsupported environment.

ArcGIS Desktop and VBA? | ArcGIS Blog (2009)

"Is VBA supported at ArcGIS 10.1?

At ArcGIS 10.1 there will not be an ArcObjects VBA SDK nor will new VBA development with ArcGIS for Desktop be supported. There will be an optional separate setup for legacy VBA support in the ArcGIS applications. This will require an additional licence authorisation similar to ArcGIS 10.

VBA will be available if needed so existing solutions can continue to work while the code is being migrated to .NET. We recommend all users with VBA code start migrating now to an add-in or custom extension using the ArcObjects SDK for .NET or Java. This is the end of the support of VBA as a development or customisation language for ArcGIS."

- See more at: https://esriaustralia.com.au/products-arcgis-software-101-faqs#7 " (2011, emphasis mine)

To actually answer your question there's quite a bit of legacy code still available at places like stackoverflow and Geographic Information Systems Stack Exchange.​  I also use a lot of the original resources such as ArcObjects 10 VBA SDK Help.

Asides from the ArcObjects-specific help, there is a wealth of internet VBA resources, mostly centered around Microsoft Office, particularly Excel if you're looking for a non-GIS coding solution.  So, if for example you want to get VBA to talk to Access then visiting MS support sites and forums would be the way to go.

Edit: Reworded last sentence so it didn't misconstrue Ethan's question.

GreggNoland
New Contributor II

Hey, Ethan....

Been working with ArcMap/VBA since ArcGIS 8.0 beta, so I'd be glad to answer any questions you have about it. But like the others have suggested, moving to something supported would be a good idea. Python can do a lot of stuff, but it can't do all of the things VBA and ArcObjects could do, so I'd suggest that if you need that much power, you move to VB.NET. The express version is free. It's even easier to build tools for ArcMap not that it has been in the past.

I'll look for your original error message from your VBA and see what I can determine from just that.

Gregg@ptarmigansoftware.com

0 Kudos
EthanDunker
New Contributor II

Gregg Noland, did you get a chance to look at my original code?

0 Kudos