My question does this code look like it will work? The code that I am referring to comes after the CommandBar is created. The code has to due with verifying links. Is there a better way of to verify the links? Any help would be appreciated.
Thank you,
rjoshi
Here is my code:
Private Sub Form_Load()
'To Hide the Database Window
DoCmd.RunCommand acCmdWindowHide
Dim custombar As CommandBar
Dim newButton As CommandBarButton
Dim newButton2 As CommandBarButton
Set custombar = CommandBars.Add("Acquistion Log", msoBarBottom, False, True)
Set newButton = custombar.Controls _
.Add(msoControlButton)
With newButton
.Caption = "Main Switchboard"
.Parameter = "Main Switchboard"
.OnAction = "Toolbar: Main Switchboard"
If .Type = msoControlButton Then
.Style = msoButtonCaption
End If
End With
.
.
.
.
custombar.Visible = True
'CommandBars("Acquistion Log"
.Visible = True
Dim varReturn As Variant
' Verify Links using one table.
varReturn = CheckLink("PSC IT Acquisition Log"
If varReturn <> True Then
hardCoded
End If
End Sub
Private Function CheckLink(strTable As String) As Boolean
' In:
' strTable - table to check
' Out:
' Return Value - True if successful; False otherwise
Dim db As Database
Dim rst As Recordset
Set db = CurrentDb
On Error Resume Next
Set rst = db.OpenRecordset(strTable, dbOpenDynaset)
' Check for failure. If the OpenRecordSet failed, then
' the link must be bad.
If Err <> 0 Then
CheckLink = False
Else
rst.Close
CheckLink = True
End If
End Function
Function hardCoded()
Dim deleted As String
Dim todayDate As Date
Dim currentDay As Integer
'Get system's date
todayDate = Date
' Extracting Day from todayDate
currentDay = Day(todayDate)
DoCmd.SetWarnings False
'If currentDay = 9 Or currentDay = 18 Or currentDay = 27 Then
'hard coded table links
'If the directory is change where the data file is kept
'Then the path has to be change to reflect the new location
deleted = "DROP TABLE [Core Data Dump]"
DoCmd.RunSQL deleted
DoCmd.TransferDatabase acLink, "Microsoft Access", "\\Psc2\Data\Ocio\SHARED\Acquisitions\Back end of PSC IT Acquisition Log\PSC IT Acquisition Data File.mdb" _
, acTable, "Core Data Dump", "Core Data Dump"
deleted = "DROP TABLE [PSC IT Acquisition Log]"
DoCmd.RunSQL deleted
DoCmd.TransferDatabase acLink, "Microsoft Access", "\\Psc2\Data\Ocio\SHARED\Acquisitions\Back end of PSC IT Acquisition Log\PSC IT Acquisition Data File.mdb" _
, acTable, "PSC IT Acquisition Log", "PSC IT Acquisition Log"
deleted = "DROP TABLE [tblObjClsDesc]"
DoCmd.RunSQL deleted
DoCmd.TransferDatabase acLink, "Microsoft Access", "\\Psc2\Data\Ocio\SHARED\Acquisitions\Back end of PSC IT Acquisition Log\PSC IT Acquisition Data File.mdb" _
, acTable, "tblObjClsDesc", "tblObjClsDesc"
deleted = "DROP TABLE [tblObjects]"
DoCmd.RunSQL deleted
DoCmd.TransferDatabase acLink, "Microsoft Access", "\\Psc2\Data\Ocio\SHARED\Acquisitions\Back end of PSC IT Acquisition Log\PSC IT Acquisition Data File.mdb" _
, acTable, "tblObjects", "tblObjects"
deleted = "DROP TABLE [tblObjectsInSystem]"
DoCmd.RunSQL deleted
DoCmd.TransferDatabase acLink, "Microsoft Access", "\\Psc2\Data\Ocio\SHARED\Acquisitions\Back end of PSC IT Acquisition Log\PSC IT Acquisition Data File.mdb" _
, acTable, "tblObjectsInSystem", "tblObjectsInSystem"
DoCmd.SetWarnings True
'End If
End Function
Thank you,
rjoshi
Here is my code:
Private Sub Form_Load()
'To Hide the Database Window
DoCmd.RunCommand acCmdWindowHide
Dim custombar As CommandBar
Dim newButton As CommandBarButton
Dim newButton2 As CommandBarButton
Set custombar = CommandBars.Add("Acquistion Log", msoBarBottom, False, True)
Set newButton = custombar.Controls _
.Add(msoControlButton)
With newButton
.Caption = "Main Switchboard"
.Parameter = "Main Switchboard"
.OnAction = "Toolbar: Main Switchboard"
If .Type = msoControlButton Then
.Style = msoButtonCaption
End If
End With
.
.
.
.
custombar.Visible = True
'CommandBars("Acquistion Log"
Dim varReturn As Variant
' Verify Links using one table.
varReturn = CheckLink("PSC IT Acquisition Log"
If varReturn <> True Then
hardCoded
End If
End Sub
Private Function CheckLink(strTable As String) As Boolean
' In:
' strTable - table to check
' Out:
' Return Value - True if successful; False otherwise
Dim db As Database
Dim rst As Recordset
Set db = CurrentDb
On Error Resume Next
Set rst = db.OpenRecordset(strTable, dbOpenDynaset)
' Check for failure. If the OpenRecordSet failed, then
' the link must be bad.
If Err <> 0 Then
CheckLink = False
Else
rst.Close
CheckLink = True
End If
End Function
Function hardCoded()
Dim deleted As String
Dim todayDate As Date
Dim currentDay As Integer
'Get system's date
todayDate = Date
' Extracting Day from todayDate
currentDay = Day(todayDate)
DoCmd.SetWarnings False
'If currentDay = 9 Or currentDay = 18 Or currentDay = 27 Then
'hard coded table links
'If the directory is change where the data file is kept
'Then the path has to be change to reflect the new location
deleted = "DROP TABLE [Core Data Dump]"
DoCmd.RunSQL deleted
DoCmd.TransferDatabase acLink, "Microsoft Access", "\\Psc2\Data\Ocio\SHARED\Acquisitions\Back end of PSC IT Acquisition Log\PSC IT Acquisition Data File.mdb" _
, acTable, "Core Data Dump", "Core Data Dump"
deleted = "DROP TABLE [PSC IT Acquisition Log]"
DoCmd.RunSQL deleted
DoCmd.TransferDatabase acLink, "Microsoft Access", "\\Psc2\Data\Ocio\SHARED\Acquisitions\Back end of PSC IT Acquisition Log\PSC IT Acquisition Data File.mdb" _
, acTable, "PSC IT Acquisition Log", "PSC IT Acquisition Log"
deleted = "DROP TABLE [tblObjClsDesc]"
DoCmd.RunSQL deleted
DoCmd.TransferDatabase acLink, "Microsoft Access", "\\Psc2\Data\Ocio\SHARED\Acquisitions\Back end of PSC IT Acquisition Log\PSC IT Acquisition Data File.mdb" _
, acTable, "tblObjClsDesc", "tblObjClsDesc"
deleted = "DROP TABLE [tblObjects]"
DoCmd.RunSQL deleted
DoCmd.TransferDatabase acLink, "Microsoft Access", "\\Psc2\Data\Ocio\SHARED\Acquisitions\Back end of PSC IT Acquisition Log\PSC IT Acquisition Data File.mdb" _
, acTable, "tblObjects", "tblObjects"
deleted = "DROP TABLE [tblObjectsInSystem]"
DoCmd.RunSQL deleted
DoCmd.TransferDatabase acLink, "Microsoft Access", "\\Psc2\Data\Ocio\SHARED\Acquisitions\Back end of PSC IT Acquisition Log\PSC IT Acquisition Data File.mdb" _
, acTable, "tblObjectsInSystem", "tblObjectsInSystem"
DoCmd.SetWarnings True
'End If
End Function