Altair_147 7/1/2011, 15:11
Boa tarde, estou querendo criar uma função para vincular as tabelas sempre que o banco for aberto. Encontrei a função abaixo.
Private Function LinkMySQLTables() As Boolean
'DAO 3.x Required
'Declare Variables...
Dim ConnectStrg As String, rst As Recordset, _
db As Database, Strg As String
'The Connection String required to connect to MySQL.
'You will need to fill in the proper information within
'this string.
ConnectStrg = "DRIVER={MySQL ODBC 3.51 Driver};" & _
"Server=myServerName;" & _
"Port=3306;" & _
"Option=16384;" & _
"Stmt=;" & _
"Database=mydatabaseName;" & _
"Uid=myUsername;" & _
"Pwd=myPassword"
'Trap any Errors...
On Error GoTo Error_LinkMySQLTables
'Open a recordset from the table the conatains
'all the table names we want to Link from the
'MySQL Database.
Set db = CurrentDb
Set rst = db.OpenRecordset("NickSeenStatus", dbOpenSnapshot)
With rst
'Fill the Recordset...
.MoveLast
.MoveFirst
'Enumerate through the Records...
Do Until rst.EOF
'Place the Table Name into the Strg string variable.
' FieldName (below) would be the Field name in your Access
' Table which holds the name of the MySQL Tables to Link.
Strg = !FieldName
'Make sure we are not dealing will an empty string..
If Len(Strg) > 0 Then
'Link the MySQL Table to this Database.
DoCmd.TransferDatabase acLink, "ODBC Database", ConnectStrg, _
acTable, Strg, Strg
End If
'move to the next record...
.MoveNext
Loop
End With
'We're done...
Exit_LinkMySQLTables:
'Clear Variables and close the db connection.
Set rst = Nothing
If Not db Is Nothing Then db.Close
Set db = Nothing
Exit Function
Error_LinkMySQLTables:
'If there was an error then display the Error Msg.
MsgBox "Link Tables Error:" & vbCr & vbCr & _
Err.Number & " - " & Err.Description, _
vbExclamation, "Table Link Error"
Err.Clear
Resume Exit_LinkMySQLTables
End Function
quando chamo a função com o comando
Call LinkMySQLTables
aparece o seguinte erro:
"Sub" ou "Function" não definida
Já procurei bastante e não consegui resolver o erro. Alguem pode me ajudar?
Obrigado