Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I open the Access 97 References form programmatically ?

Status
Not open for further replies.

Cosmark

Technical User
Apr 18, 2001
9
CY
I am trying to open the References form (Tools-References in the VB toolbar) programmatically with no success. Any ideas on how I can do it from a button on a form through a macro or VB code ? I am using Acces 97.

Your help appreciated.

Thanks
Cosmark
 
yes, you can create a macro with 2 actions.
Action 1
OpenModule
Module Name
You Need to Provide the Name of an Existing Module

Action 2
SendKeys
KeyStrokes
%(tf)

But if all you want to do is ensure that the references are "refreshed", then you can use this code

First create a query qryTestRefs that uses the Left Function
SELECT Left([companyname],1) AS ComName
FROM Customers;

Then Call the Function CheckRefs()


Function CheckRefs()
Dim db As database, rs As Recordset
Dim X
Set db = CurrentDb

On Error Resume Next

' Run the query qryTestRefs you created and trap for an error.
Set rs = db.OpenRecordset("qryTestRefs", dbOpenDynaset)

' The if statement below checks for error 3075. If it encounters the
' error, it informs the user that it needs to fix the application.
' Error 3075 is the following in Access 97 and Error 3085 in 2K:
' "Function isn't available in expressions in query expression..."

' Note: This function only checks for the error 3075. If you want it to
' check for other errors, you can modify the If statement. To have
' it check for any error, you can change it to the following:
' If Err.Number <> 0

If Err.Number = 3075 Or Err.Number = 3085 Then
MsgBox &quot;This application has detected newer versions &quot; _
& &quot;of required files on your computer. &quot; _
& &quot;It may take several minutes to recompile &quot; _
& &quot;this application.&quot;
Err.Clear
FixUpRefs
End If


End Function

Sub FixUpRefs()
Dim r As Reference, r1 As Reference
Dim s As String

' Look for the first reference in the database other
' than Access and Visual Basic for Applications.
For Each r In Application.References
If r.Name <> &quot;Access&quot; And r.Name <> &quot;VBA&quot; Then
Set r1 = r
Exit For
End If
Next
s = r1.FullPath

' Remove the Reference and add it back.
References.Remove r1
References.AddFromFile s

' Call a hidden SysCmd to automatically compile/save all modules.
Call SysCmd(504, 16483)
End Sub


PaulF
 
Thanks a million PaulF. Excellent code and straight to the point. Keep up the good work.

Cosmark
 
Also you can look at thread702-99187 in what I posted idea how to simplify references creating after DBs copy into another machine etc.

Aivars
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top