Update VBA Code to work on ACCDE file instant of MDE - ms-access

I have a VBA code in Access for some function for MDE file, I want to update the function to work on ACCDE file instant of MDE.
Where can i send my code to update it?

Your question doesn't provide enough clarity to give you a definitive answer. That said, I can make a guess at what might be your request.
If the issue is with declare statements at the head of your code you may need to add PtrSafe to them.
e.g., Instead of just:
Private Declare Sub Sleep Lib "kernel32" (ByVal lngMilliSeconds As Long)
it would be
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal lngMilliSeconds As Long)
If however, you have people running different versions of office and VBA you'll want to encapsulate it in a precompiled (#) if statement to ensure backwards compatibility with earlier VBA versions.
e.g.,
#If VBA7 Then
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal lngMilliSeconds As Long)
#Else
Private Declare Sub Sleep Lib "kernel32" (ByVal lngMilliSeconds As Long)
#End If
Hope that helps.

Related

Exit an Access VBA Macro with an exit code returned to the shell / Scheduled Task Manager?

I'm running a scheduled task in Windows Server 2003. When the scheduled task runs, it calls a VBA Macro which runs, does some database stuff, then exits.
The VBA Macro needs to return a non-zero value to the Shell / Scheduled Task Manager if something goes wrong in the Macro (for instance a database goes down).
Is it possible to return a non-zero value from the vba macro to notify the Scheduled Task Manager that something has gone wrong? I'd like to be able to fish the value out of SchedLgU.txt so I can be notified when something goes wrong.
If you're willing to use an API call it can:
Private Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)
In your code, you can exit with a value, like 7, for the example below:
Call ExitProcess(7)
Note that calling the above will immediately exit Access without any prompt or saving or anything. It should be the very last thing you do.

How to save an Access database using VBA program?

In order to save a record in my MSAccess database via a VBA application, I wrote the following. But when running the code it discards acCmdSaveRecord as an undefined variable. Can anyone give some leads about this?
Option Explicit
Private Sub SavingAccessDB()
DoCmd.RunCommand acCmdSaveRecord
End Sub
In the VBA Window, select Tools menu, then References...
Tick the checkbox:
Microsoft Access xxx Object Library

Search through folders of html for user generated string.

Visual Studio 2010,
Visual Basic .NET
I have been working on a program that has a JSON generated table of contents and a WebBrowser control that only displays the html we have given them. Now I need to give them the ability to search for strings inside the html. Not just the currently opened html page in the WebBrowser object, but the entire group of html files which are in various folder.
There is a Main folder with several folders in it. Each of those folders only have one folder in it. But inside that one folder is several html files. (Not sure if knowing the folder structure will help at all)
I have no code for this since I have never done anything like this before, just wanting someone to point me in the right direction.
Since html files are just text files you can use this approach.
To create this example I created 2 directories in my c:\temp directory, I named them InHere and ChildofInHere. I put ChildofInHere in InHere obviously. I then added a file called SomeFile.html and just put the word "Cheese" in it. Here is the code I then created and ran against it.
Private _TextFound As Boolean = False
Private Sub Button10_Click(sender As System.Object, e As System.EventArgs) Handles Button10.Click
FindTheText("C:\temp\InHere", "cheese")
MessageBox.Show(_TextFound)
End Sub
Private Sub FindTheText(sDirToLookIn As String, sTextToFind As String)
If IO.Directory.Exists(sDirToLookIn) Then
Dim di As New IO.DirectoryInfo(sDirToLookIn)
For Each dii As IO.DirectoryInfo In di.GetDirectories
FindTheText(dii.FullName, sTextToFind)
Next
If IO.File.Exists(sDirToLookIn & "\SomeFile.html") Then
If IO.File.OpenText(sDirToLookIn & "\SomeFile.html").ReadToEnd.Contains(sTextToFind) Then
_TextFound = True
End If
End If
End If
End Sub
.NET makes working with files and directories so easy. Hope this helps.

VBA Access Compile Error variable not defined

I have this script that I want to use to move folders for archive this is my code :
Public Function modbalsmovearhive()
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.MoveFile "H:\Credit_Bals*.xls", "H:\Bals_Archive\"
End Function
Now when I go to run it I get the Compile Error variable not defined. Can someone assist me with the best way to resolve this error.
I just tested the code and it works. Make sure Option Explicit is not On, and also make sure have included all the libraries you are using in your code.
EDIT: It is NOT good practice to have Option Explicit Off, so if you do want to keep it on, make sure all your variables are declared and your libraries included.
I think you may have forgotten to dimension the object, I'm guessing using:
Dim FSO As FileSystemObject
Also make sure that you have the reference checked for Microsoft Scripting Runtime.
Also note that after putting define variable option OFF, existing module wouldn't change, that is, existing module will continue to have Option Explicit. In that case you need to copy code to a new module.

In VBA, cannot use Access.Application object

This does NOT work:
Sub X()
Dim A As Access.Application
Set A = CreateObject("Access.Application")
'Do Stuff
End Sub
However, this DOES work:
Sub X()
Dim A As Object
Set A = CreateObject("Access.Application")
'Do Stuff
End Sub
I know they do virtually the same thing, but can anyone tell me how to make an access.application object? I should add that I have Crystal Reports 11 and on my last upgrade, it may have 'unregistered' some VBA DLLs.
(Update 2009-06-29)
In response to the first 2 questions, I am using MS Access VBA to control some other Access & Excel files. Since this will only ever run on my local machine, I can guarantee that Access will always be installed. I have also referenced the "Microsoft Access 11.0 Object Library" (MSACC.OLB).
I know there's ways around this, i.e. use early binding when coding, and switch to late binding when running it, I just don't understand why the early binding method doesn't work at all on my machine (Of course, the code works fine on another machine with Access).
If you are writing this in Access there is no need to do that as the Application object is already there for you. If you are writing this in Excel or Word then you need to add a reference to the Access Library. Go to Tools/References and look for Microsoft Access XX Object Library
Hello,The code that you say is not working is legal syntax. What error are you getting? When does it occur? Do you know the line of code it happens at?
Just as a side note, this is legal syntax as well: Dim accApp As Access.Application
Set accApp = New Access.Application
But to be clear, the CreateObject Syntax is legal and not the source of the problem.
Try Detect And Repair from the Help menu in MS Access. Worked perfect for me.