[SOLVED]Access2Base Macro
Sub DBOpen(Optional poEvent As Object) If GlobalScope.BasicLibraries.hasByName("Access2Base") then GlobalScope.BasicLibraries.loadLibrary("Access2Base") End If Call Application.OpenConnection(ThisDatabaseDocument) End Sub
Sub Main DoCmd.OpenForm("Strength") End sub
Sub DBClose(Optional poEvent As Object) Call CloseConnection() End Sub
=====================================================================================================
Hopefully this is the right forum for this post, if not please move it as appropriate.
I am using Base after having worked in in Access.
I am wanting a simple Macro to open a form by clicking a button.
I followed the Access2Base documentation and entered this snippet initially:
Sub DBOpen(Optional poEvent As Object)
If GlobalScope.BasicLibraries.hasByName(“Access2Base”) then
GlobalScope.BasicLibraries.loadLibrary(“Access2Base”)
End If
Call Application.OpenConnection(ThisDatabaseDocument)
End Sub
Sub DBClose(Optional poEvent As Object)
Call CloseConnection()
End Sub
then i added this macro to open a form named Strength:
Sub Macro1
DoCmd.OpenForm “Strength”, acNormal, “”, “”, , acNormal
End sub*
On pressing F5 i get an “object variable not set error”.
If i remove the DoCmd. i get a “Sub-procedure or function procedure not defined” error
any ideas or suggestions would be greatly appreciated.
thanks,
shaun
Appreciate the help. This is what my final code looks like:
Sub DBOpen(Optional poEvent As Object) If GlobalScope.BasicLibraries.hasByName("Access2Base") then GlobalScope.BasicLibraries.loadLibrary("Access2Base") MsgBox("Access2Base Lib loaded...") End If Call Application.OpenConnection(ThisDatabaseDocument) End Sub
Sub Main DoCmd.OpenForm("Strength") End sub
Sub DBClose(Optional poEvent As Object) Call CloseConnection() End Sub
Sub IsAccess2BaseLoaded()
If GlobalScope.BasicLibraries.isLibraryLoaded("Access2Base") Then
MsgBox("Access2Base is loaded.")
Else
MsgBox("Access2Base is NOT loaded.")
End If
End Sub
Glad to see you got it going…
Still trying to rap my mind around this, being a LO newbie.
I am about to try your example and see if that fixes things.
shaun
I set up a new Basic Module and add the open and close macros in the database document so they will always go with the odb where they are needed. You can try other setups as well. There is a message here in the forum with a collection of links to Base and macro documentation. If I can find it I may come back here and link it. documentation link
You need to go to Base menus, Tools->Customize and Events Tab. There you click on the “Open Document” and click “Macro” to assign the DBOpen macro. It will then load the library whenever you open the database. In that way, the library may be used at will while the database is in use. The DBClose event is to go away clean when you are done in the database. They suggest executing it on the “View is going to be closed” event.
You will have to save, close and reopen the database for the action of “Open Document” to run.
I use a different macro to open a form when my database opens so I added the DBOpen code to it so both would execute on the Open Document event. Then I can use Access2Base library in my other macros as long as the database is running.
Does that make any more sense?
The next step is saving and closing a form with a button.
i tried:
Sub CloseMacro()
Dim myForm as object
Set myForm = Application.AllForms("Appearance")
Close Application.AllForms("myForm")
End Sub
and also tried:
Sub closemac
DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close
End Sub
The second one works in Access but neither work in Base.
Any suggestions?
thanks
Shaun
There are several ways. Using Access2Base I use “mClose” see code:
Sub FormClose
DoCmd.mClose(acForm,"Foods") 'use your form's name in the quotes
End Sub
There is a save option parameter for mClose. I think it’s acSavePrompt as third (optional) parameter?? Sorry. I use it to close a menu form with no data…
Forms("myForm").mClose
The use of mClose instead of Close (like in MSAccess) seems strange, indeed. This is simply because Close is a reserved word in LO Basic. This forbids to write a Sub, a Function or a Method with Close as name.
JPL
I took a look at the Close statement on the A2B extension website and it is making more sense to me. I also used an example provided by another poster as well to come up with:
Sub CloseMacro1
DoCmd.mClose(acForm,"Strength",acSavePrompt)
End Sub
There is a learning curve here but definitely easier than Uno or Star Office Basic.
thanks
Shaun
It has been a fun project, maybe it will even help him.
I did add the save function to my macro, it now looks like this:
Sub CloseMacro1
DoCmd.mClose(acForm,"Strength",acSavePrompt)
End Sub
Try putting the following extra line in the code where you load the library:
The message box will let you better know if the library is loaded when you open your LO base document.