How to add new records in access via vba - vba

'Hi all,
I made VBA, this code add new records into access database. But the problem is when multiple run the vba i get error message as "Unrecognized database format" "Run time error 3343.
Can any one suggest me why i am getting this error. My code is below

I'm guessing you are using VBA to send data from Excel to Access. Please see the links below. Those links should answer pretty much all of your questions about this topic.
http://www.excel-spreadsheet.com/vba/dao_ado.htm
http://www.erlandsendata.no/english/index.php?d=envbadacexportado
http://www.erlandsendata.no/english/index.php?d=envbadacexportdao
http://www.datawright.com.au/excel_resources/excel_access_and_ado.htm
You can import from Excel into Access as well.
http://www.accessmvp.com/KDSnell/EXCEL_Import.htm

Related

Creating a working copy of an old Access 2010 database

I am tasked with fixing some bugs that an access 2010 database, written 10 or so years ago, has. The database has been functioning but has a few bugs in report generation that need to be fixed (ie: bugs are not impeding overall functionality).
Since I am relatively new to access 2010, I wanted to create a working copy of the entire database, VBA and all, so that I could get into the VBA code and figure out what is causing the bugs without accidentally sending some of the automatic emails or changing pertinent information in the data. I have tried saving the database with a new name, copying it in the folder and pasting elsewhere, and creating a backup and saving that elsewhere.
Each attempt yields the same issue: the VBA project not being readable. It gives the following message when I open any copy:
if included picture doesn't load: tl/dr: database cant be opened because VBA project cant be read, if "ok" is clicked vba project will be deleted..I have searched high and low, asked everyone that has used the database, nobody knows how to fix the issue and I do not feel comfortable changing anything in the live copy.
Any assistance would be greatly appreciated. Thank you in advance.
One option you might try is to create a new blank database file and attempt to import all of the database objects from a copy of your target database into the new database file using the import wizard. If that's successful it won't be an exact replica of the previous database with regards to settings, but will include all of the database objects/code at least.

How does one write VBA code to get data from an ODBC source?

I'm looking for some straightforward documentation on how exactly to write VBA code to get info from an ODBC source. It shouldn't be that hard, but I can't find it anywhere.
I don't want to populate a spreadsheet with my data. I just want to read the data and process it using local variables, and then do other tasks in VBA based on the value of that data.
I used to think I was pretty good at searching Google for stuff, but I can't find a clear-cut example.
Can anyone point me to a reference for CRUD operations using ODBC in VBA? My "connection string" is just the name of the DSN. I know this works, because I can use Get Data -> From Other Sources -> From ODBC and I can import the data just fine. Therefore, I know it's not my data source that's at fault, and it's not the ODBC that's at fault.
But when I try to follow many of the examples I've found, it says, for example, to test for (rs.EOF and rs.BOF) and if they're both true, you have an empty recordset. However, when I go to test for rs.EOF, Excel crashes.
I'm about ready to pull out what little hair remains. Are there any examples of "how to read data from an ODBC source" that are current?

Excel VBA - Remember SQL ODBC User/Password

First time here, so I hope to get my answer, I looked throughout the Google but I couldn't find the answer.
Well, I got VBA code which refresh a code in SQL on Exel.
VBA code: Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
It's asking everytime my ODBC login/password and I try to refresh manually, and I'd like to run automatically by saving those information on Excel Cells or in VBA directly (I prefer a variable that is linked in excel cells in "Validação de Dados" sheets). And after that, making it better by forcing the user to insert those information in a form (to keep better looking).
But the problem is that everytime I tried to run the macro, it gets an error (something like "authenticantion failure").
My SQL code in Excel location:
Asking about my user and login:
Error getting by not saving user/login:
Office version: Microsoft Office 365 Business
Thanks everyone!
You should be able to use windows integrated authentication as well if you have an SQL Server. You'd have to add your user in SSMS.
https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/using-integrated-authentication?view=sql-server-2017
I managed to ask the password from the standard window with this code:
ActiveWorkbook.Worksheets("Base").ListObjects(1).QueryTable.Refresh
"Base" is the name of your worksheet, and ListObjects(1) is if you have only one SQL query.

Accessing Google Calendar Events with MS Access Database

I wrote an access database several years ago that used VBA to pull events from my Google calendar and present them on a report. It worked great for a couple of years but then Google must have made a change and it stopped working. I didn't have time to figure it out at the time so I let it go but now I would like to see if I can get my app working again. I've been Googling all morning trying to figure this out but I'm just not finding anything that's helpful. I've looked thru the Google API website but it doesn't address VBA so I'm wondering if it's no longer supported???
So my question: is it still possible to retrieve Google calendar data from MS Access using VBA? If so, can anyone point me towards resources that explain how to do it?
Thanks for any help,
Chris
You should probably post the code you have. Also, consider recording a Macro in Excel, and modify it slightly to work in Access. The Macro Recorder can generate a lot of code for you (actually, you will probably end up with too much code). You can't record a Macro using Access, but the Excel object model and the Access object model are very similar.

Dump MS Access Macro object info from VBA code

I have a project in which I need to compare different versions of an Access 2003 database against each other. We're not interested in the data in the tables. We're only interested in the objects that describe the database. I.e. Form objects, Report objects, QueryDefs, TableDefs etc.. The databases are fairly large so the approach is to dump all the descriptions for objects of interest into a text file by running a VBA app in each of the databases and then comparing the results in a diff viewer.
I've been looking around for several days to find out how to dynamically dump access 2003 macro content from within VBA. Please don't confuse this with dumping VBA code from VBA.
I know about Application.CurrentDB.AllMacros to get a list of macros in the active access database. But I can't get at the macro object from Macro(MacroName).SomeProperty because the macro isn't open. So I've been trying to look for a way to open the macro and haven't found a way to accomplish this through VBA.
Any help on the topic would be appreciated.
Thanks!
You can export macros with the undocument Application.SaveAsText:
Application.SaveAsText acMacro ,"AutoKeys", "AutoKeys.txt"
...saves the AutoKeys macro to whatever the current directory is.
You could manually ask Access to convert the macros to VBA. There is an option for that, I think when you right click the macro. After that you can compare the generated VBA.
See the following page for a list of utilities to compare Access databases
http://www.granite.ab.ca/access/thirdparty.htm