New to ArcMap VBA

11896
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
GreggNoland
New Contributor II

Yeah, but it was hard to understand where you’re reference to the specific line number was… the extra line spacing caused some confusion..

Free free to email it to me directly… gregg@ptarmigansoftware.com <mailto:gregg@ptarmigansoftware.com>

I’ll gladly take a look at it…

0 Kudos
ChadStidham
New Contributor II

As far as connecting to an Access database I'd recommend the pypyodbc module:

import pypyodbc

DB = r'C:\Folder\test.mdb'; DRV = '{Microsoft Access Driver (*.mdb)}'; PWD = ''
conn = pypyodbc.connect('DRIVER={};DBQ={};PWD={}'.format(DRV,MDB,PWD))
SQL = 'SELECT * FROM Table'

records = conn.cursor().execute(SQL).fetchall()

for record in records:
    print record

conn.close()

I also recommend looking into setuptools and pip for installing python modules that do not come with the standard install:

setuptools 20.0 : Python Package Index

pip 8.0.2 : Python Package Index

RalfSchmidt
New Contributor III

I just want to note that VBA in ArcMap will be there for probably as long as ArcMap is there. Citation:

"Esri will continue to ship Microsoft Visual Basic for Applications (VBA) compatibility setup with ArcGIS as long as we continue to ship ArcMap or until Microsoft notifies us that we can no longer distribute this."

from: http://downloads2.esri.com/support/TechArticles/W32809_DEPRECATION_PLAN_FOR_ARCGIS_10_3_and_10_2_x__...

Although we never used VBA in customer projects (because it's not suitable for professional software development) I still use it for prototyping, experiments, and one-off data processing because it's more powerful than python and you can change code during debugging to a much higher degree compared to C# and VB.NET.

0 Kudos
AdrianWelsh
MVP Honored Contributor

So the question is, how long will ArcMap be around? Would it be safe to assume that 10.4 will likely be the last version of ArcMap? And then Pro will just take over from there?

0 Kudos
XanderBakker
Esri Esteemed Contributor

10.4 will be launched shortly and there will probably be a 10.4.1. Taking the 6 year of support cycle you will be "save" with ArcMap until 2022.

BUT, do you really want to get stuck with a solution in a 32 bits environment when you could do this in a 64 bits environment and benefit from what Pro has to offer?

XanderBakker
Esri Esteemed Contributor

Ralf Schmidt is totally right that using .NET can be very powerful and looking at the workflow as the OP posted in another thread here: Help with Run time error 91 it could be the way to go, since a selection is made with the tool which loads a form with a list of selected features allowing the user to select one of them and then it does something in Access.

BUT... I totally agree with James Crandall if you can change the workflow and move the data into a File Geodatabase a wealth of capabilities will be enabled.

A slide I like to include in my presentations on Python in the ArcGIS Platform is the one below:

... and yes, I truly believe that when you are not using Python you are probably doing thing the "hard way".

True that using .NET allows you to enhance the UI/UX of the workflow, but do you really want to introduce the additional complexity into your project.

To give you some pointers (based on a possible Python implementation):

BUT to show a list of features found in a form you will probably have to use something like TKinter.

The advance of Python is that you could make code that works for ArcMap and for ArcGIS Pro. You will not be able to do that with .NET, since ArcMap is based on ArcObjects and ArcObjects no longer exists in Pro.

GreggNoland
New Contributor II

Good rule of thumb…..

If you’re needing a more user friendly UI for casual users, interfacing with other enterprise systems via databases or web services, or need more fine grained access to AO for things like stepping through the feature connectivity in a geometric network, .NET is the way to go….

AndrewQuee
Occasional Contributor III

I agree that despite ongoing warnings, Esri probably will continue to have VBA compatibility in 10.x (it costs them nothing to roll it in after all), but I doubt they will offer any support at all.  I suspect if you were to take a VBA issue to support they would respond with 'not a supported feature, please update your code'.  That said, you never know when they might yank the carpet out from underfoot - they have been making this call for at least seven years.

Fair call on prototyping, and that is essentially what we were doing as well.  Unfortunately a lot of the time schedule demands mean that the prototype gets badged as production for small projects instead of going through full product development...

0 Kudos
DuncanHornby
MVP Notable Contributor

I found Ralf Schmidt​ answer most similar to my experiences. I uses VBA all the time for rapid prototyping of functions that I will ultimately want to convert into VB .NET. I find using Visual Studio a faff when all I want to do is test if Interface X works in the way I expect it to (because I can't tell from the API)? Rather than create an addin, waste time waiting for visual studio to compile then run in debug mode I just do it in VBA, way more quicker.

But as everyone says Python and its bewildering array of modules is here to stay and has replaced VBA as the de facto scripting environment.

I was curious about who still used VBA so created the following poll which I suspect some of you have already contributed to.

0 Kudos
curtvprice
MVP Esteemed Contributor

VBA has been deprecated since ArcGIS 10.0 (years!)

That said, it is still available with 10.3.1 so you could use it. You (and all users of your app) do need to install "VBA Compatibility" which is a separate installer from the main Desktop install.  All the normal VBA commands to control another application should work -- but you do need to tackle ArcObjects to interact with ArcMap, which is a heavy lift especially if you are unfamiliar with ArcMap. I'd get some assistance from someone who knows the software better.

If you decide to tackle doing this in python at some point (good idea) -- it sounds like you are trying to control the access application. If that's the case, I highly recommend installing PyWin32 and using win32com to control the application.

0 Kudos