SetOptions

B

BS Galactica

I am trying to set several options using VB in an mdb I am creating in code.
The options I am trying to set are 'Track Name AutoCorrect Info' and 'Perform
Name AutoCorrect' to False and 'Compact on Close' to True.

They seem to be settable within the current database but not on a database
being created. Is there a way to set these options on an mdb while one is
trying to create it?

Thanks.
 
6

'69 Camaro

Hi.

You probably already did this when you created the new MDB file, but if not,
then you need to set a reference to the DAO library. Then you can paste in
code from the following example:

Private Sub OKBtn_Click()

On Error GoTo ErrHandler

Dim accApp As New Access.Application
Dim db As DAO.Database

Set db = CreateDatabase("C:\Test\NewDB.mdb", dbLangGeneral)

'-------------------------------------------------------------------------
' Do whatever you need to do in your new database . . .
'-------------------------------------------------------------------------

db.Close

DoEvents ' Give OS chance to save file before accessing it.

'-------------------------------------------------------------------------
' Connect to the new database using an instance of
' Access.
'-------------------------------------------------------------------------

accApp.OpenCurrentDatabase "C:\Test\NewDB.mdb", True
accApp.SetOption "Track Name AutoCorrect Info", False
accApp.SetOption "Perform Name AutoCorrect", False
accApp.SetOption "Auto Compact", True

CleanUp:

Set db = Nothing
Set accApp = Nothing

Exit Sub

ErrHandler:

MsgBox "Error in OKBtn_Click( ) in " & Me.Name & " form." & _
vbCrLf & vbCrLf & Err.Number & vbCrLf & Err.Description

GoTo CleanUp

End Sub

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)

- - -
When you see correct answers to your question posted in Microsoft's Online
Community, please sign in to the Community and mark these posts, so that all
may benefit by filtering on "Answered questions" and quickly finding the
right answers to similar questions. Remember that the best answers are often
given to those who have a history of rewarding the contributors who have
taken the time to answer questions correctly.
 
M

MiSsisB0sS

Hi Gunny,

I was having exactly the same problem trying to set the auto compact option
in another database - and your code works a treat.

Thanks a million
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top