sportsguy
Finance wiz, Access hack
- Local time
- Today, 04:38
- Joined
- Dec 28, 2004
- Messages
- 358
Why does the DoCmd.TransferDatabase work in the Immediate window, but not in the Sub, which has always worked in the past?
Debug.Print
Microsoft Access
\\celerradc2\csdisaster$\Scorecard\cp.accdb
PORTAL
The following works in the IMMEDIATE window:
DoCmd.TransferDatabase acLink, "Microsoft Access", "\\celerradc2\csdisaster$\Scorecard\cp.accdb", acTable, "PORTAL", "PORTAL"
just very confused why this subroutine doesn't work as it always has in the past. . . and works in the immediate window. .
ERROR MESSAGE:
3125 '' is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long.
any suggestions?
thanks in advance. . .
Code:
Public tblname As String
Public tblNewname As Variant
Public pstrDatabasePath As String
Public Const dbType As String = "Microsoft Access"
Public Sub AttachTable(ByVal pstrDatabasePath, ByVal tblname, Optional ByVal tblNewname)
On Error GoTo Attach_Err
Debug.Print dbType
Debug.Print pstrDatabasePath
Debug.Print tblname
If IsNull(tblNewname) Then tblNewname = tblname
With DoCmd
.DeleteObject acTable, tblname
.DeleteObject acTable, tblNewname
.TransferDatabase acLink, dbType, pstrDatabasePath, acTable, tblname, tblNewname
End With
Exit Sub
Attach_Err:
If Err.Number = 7874 Then
Debug.Print Err.Number & " " & Err.Description & " when deleting table from local database - Macro continues"
Resume Next
ElseIf Err.Number = 3011 Then
MsgBox "Wrong Access database! Please select the correct Access database!", vbCritical, "FP&A"
Else
MsgBox Err.Number & " " & Err.Description & " " & tblname, vbCritical, "FP&A"
End If
End Sub
Debug.Print
Microsoft Access
\\celerradc2\csdisaster$\Scorecard\cp.accdb
PORTAL
The following works in the IMMEDIATE window:
DoCmd.TransferDatabase acLink, "Microsoft Access", "\\celerradc2\csdisaster$\Scorecard\cp.accdb", acTable, "PORTAL", "PORTAL"
just very confused why this subroutine doesn't work as it always has in the past. . . and works in the immediate window. .
ERROR MESSAGE:
3125 '' is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long.
any suggestions?
thanks in advance. . .