By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,122 Members | 921 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,122 IT Pros & Developers. It's quick & easy.

Changing a Library Reference

P: n/a
Some months ago, we requested help from this newsgroup on how to replace
the library reference of a database with another library reference,
prior to creating an MDE. I got the following answer from Stephen K.
Young, which does the job:
In message <ah************@ID-65843.news.dfncis.de>, Stephen K. Young
<s@k.y.invalid> writes
Using automation you can temporarily replace a developer library reference
with a compiled library reference. Sample code below. Then continue with
automation to compile the .Mde as before. Afterwards you probably want to
use automation again to reverse the front-end references back to your
un-compiled developer library.

- Steve
For lngRef = appAccess.References.Count To 1 Step -1 ' loop backwards,
one-based
Set ref = appAccess.References(lngRef)
If ref.Name = strRefName Then
appAccess.References.Remove ref
Endif
Next lngRef

<Snip>

I added a:

AppAccess.OpenCurrentDatabase (DbFileName)

at the start to open the database with which to work.

This works fine, apart from one minor problem - when the database is
opened, the AutoExec or Startup form starts running unless I keep my
finger on the shift key.

Is there another way of opening the database, or of preventing the code
from running?

Thanks
--
Zippy S

Email: Zi********@thedessers.com
Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Zippy <Zi***@111.1.1.1> wrote in message news:<fn**************@thedessers.com>...
Some months ago, we requested help from this newsgroup on how to replace
the library reference of a database with another library reference,
prior to creating an MDE. I got the following answer from Stephen K.
Young, which does the job: .... Is there another way of opening the database, or of preventing the code
from running?


Zippy emailed me directly, so I am posting a reply here.

In my application startup code, I use the trick of checking the
command line parameter to see if any special processing should be
performed. For example, if the command line has a substring
";Continue;", then my startup code knows to skip certain processing
and let automation take control. (Other substrings delimited by
semicolons can be used to perform additional branching.)

In the startup code, I have something like this:

If (InStr(Command$(), ";Continue;") <> 0&)
... ' skip user setup
Else
... ' perform user setup
End If

The code below is a sample programmer function that uses automation to
reset the library reference to a compiled version, prior to compiling
the application itself as a .Mde. (This step needed because you cannot
compile an application unless its library references are also
compiled.) This code resides in a separate programmer application, NOT
the user application.

In the code, the following line sets the command line substring to
control the application startup:

appAccess.SetOption "Command-Line Arguments", ";Continue;"

In addition, there is some automation code to close any startup forms.
(The user application uses the standard technique of opening a hidden
startup form to know when the user tries to shut down. My startup code
could skip opening the hidden form entirely, based on the command
line, and maybe it does, but I can't remember now and this code checks
for it anyway.)

Anyway, here is the code to reset a library reference. Watch for
word-wrap. I've removed a few lines relevant to me only, so I have not
actually tested this precise version.

' Replace a reference in an external Access session
' Manipulating references may lose global variables in the db, so the
calling program cannot depend on globals.
' Mde or compiled databases cannot manipulate references at all.
' Example: RefReplace "E:\MyPath\MyApp.Mdb", "MyLib",
"E:\MyPath\MyLig.Mde" ' change it
' Example: RefReplace "E:\MyPath\MyApp.Mdb", "MyLib",
"E:\MyPath\MyLig.Mdb" ' put it back

Public Function RefReplace(strDbName As String, strRefName As String,
strRefPath As String) As Boolean

On Error GoTo ErrExit
If Not isPathOk(strRefPath) Then
MsgBox "The reference path does not exist: " & strRefPath
Exit Function
End If

' open the database via automation
Dim appAccess As Access.Application
Dim ref As Reference, lngRef As Long
Set appAccess = CreateObject("Access.Application." &
Left$(SysCmd(acSysCmdAccessVer), 1)) ' use correct version
appAccess.UserControl = True ' this forces appAccess.Visible = True
automatically
appAccess.SetOption "Command-Line Arguments", "continue;" &
cstrCmdDebug
appAccess.OpenCurrentDatabase strDbName, False

' close the hidden form that may be running and set the shutdown
flag
If appAccess.SysCmd(acSysCmdGetObjectState, acForm, "fsysSystem") <>
0 Then
appAccess.Forms("fsysSystem").gisAppShutDown = True
appAccess.DoCmd.Close acForm, "fsysSystem", acSaveNo
End If

' close any other forms such as frmDbBrowse or frmClassif
For lngRef = appAccess.Forms.Count - 1 To 0 Step -1
appAccess.DoCmd.Close acForm, appAccess.Forms(lngRef).Name,
acSaveNo
Next lngRef

' remove the prior reference if any
'Debug.Print appAccess.References.Count
DoEvents
For lngRef = appAccess.References.Count To 1 Step -1 ' loop
backwards, one-based
Set ref = appAccess.References(lngRef)
If ref.Name = strRefName Then
appAccess.References.Remove ref
Exit For
End If
Next lngRef
Set ref = Nothing

' add new reference
DoEvents
On Error Resume Next
appAccess.References.AddFromFile strRefPath
If Err <> 0& Then
MsgBox Err.Description, vbCritical, "RefReplace error adding
reference to " & strRefPath
Err.Clear
Else
DoEvents
appAccess.SysCmd 504, 16483 '<- undocumented call for Compile All
without a module open
If Err <> 0& Then
MsgBox Err.Description, vbCritical, "RefReplace error compiling
all"
Err.Clear
End If
If appAccess.isCompiled = False Then
MsgBox "Database " & strDbName & " was not compiled completely,
perhaps there is a compile error.", vbInformation, "Not Compiled"
End If
End If
appAccess.Quit acQuitSaveNone
If Err <> 0& Then
MsgBox Err.Description, vbCritical, "RefReplace in appAccess.Quit"
Err.Clear
End If
Set appAccess = Nothing
If Err <> 0& Then
MsgBox Err.Description, vbCritical, "RefReplace in Set appAccess =
Nothing"
End If
Exit Function

ErrExit:
MsgBox Err.Description
Stop
Resume
End Function
Nov 12 '05 #2

P: n/a
In article <25**************************@posting.google.com >, Stephen K.
Young <st***********@hotmail.com> writes
Zippy <Zi***@111.1.1.1> wrote in message
news:<fn**************@thedessers.com>...
Some months ago, we requested help from this newsgroup on how to replace
the library reference of a database with another library reference,
prior to creating an MDE. I got the following answer from Stephen K.
Young, which does the job:

...
Is there another way of opening the database, or of preventing the code
from running?


Zippy emailed me directly, so I am posting a reply here.


[Snip solution]

It seems that Zippy's posts to this newsgroup have not got through, so
she asked be to forward her thanks. The solution was perfect and has
worked a treat. Many thanks to Stephen.
--
Les Desser
(The Reply-to address IS correct - hope Swen ignores it))
Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.