Calling Functions...

Chimp8471

Registered User.
Local time
Today, 22:26
Joined
Mar 18, 2003
Messages
353
i have a module that is called "Getpath" and want it to be used on my main form when the db opens...

i am lead to believe i need to use the on load event but am not sure how to actually call the module, any advise please

Andy
 
You can't call a module - you call one of the subs or functions within the module.
 
hmmm...now i am lost....

this is the code in that module i was on about..

Code:
Function Reconnect()
Dim ref As Reference
Dim db As Database, source As String, path As String
Dim dbsource As String, i As Integer, j As Integer
Set db = DBEngine.Workspaces(0).Databases(0)

For i = Len(db.Name) To 1 Step -1
If Mid(db.Name, i, 1) = Chr(92) Then
path = Mid(db.Name, 1, i)
'MsgBox (path)
Exit For
End If
Next

For i = 0 To db.TableDefs.Count - 1
If db.TableDefs(i).Connect <> " " Then
source = Mid(db.TableDefs(i).Connect, 11)
'Debug.Print source
For j = Len(source) To 1 Step -1
If Mid(source, j, 1) = Chr(92) Then
dbsource = Mid(source, j + 1, Len(source))
source = Mid(source, 1, j)
If source <> path Then
db.TableDefs(i).Connect = ";Database=" + path + dbsource
db.TableDefs(i).RefreshLink
'Debug.Print ";Database=" + path + dbsource
End If
Exit For
End If
Next
End If
Next

End Function

so what exactly is it i should be calling in my form on load then??
 
is that all i should type in the on load box of the properties window??
 
Just to be safe, the following rules should be applied to functions you wish to call from a query, form, or report:

1. Always define the function in a general module.

2. Remember to declare it a Public Function (not just a function).

If it ain't public, only the code in its defining module can use it.
 

Users who are viewing this thread

Back
Top Bottom