AccessVBA バックアップ画面

Option Compare Database

Private Sub Form_Open(Cancel As Integer)
Me.PictureType = 0
Me.Picture = BgImageDataPath
Me.txtフォルダパス.Value = “C:\Users\golive\Desktop\Access_BackUp”

Me.バックアップ履歴リスト.ColumnCount = 3
Me.バックアップ履歴リスト.RowSourceType = “Table/Query”
Me.バックアップ履歴リスト.RowSource = “tbバックアップ履歴”
End Sub

Private Sub TOPへ戻るボタン_Click()
Application.Echo False ‘画面の描画を止める
CloseForm (“fmバックアップ”)
Application.Echo True ‘画面の描画を行う
End Sub
Private Sub バックアップ処理ボタン_Click()

On Error GoTo err_Shori:

Dim FileName As String
FileName = Format(Now, “yyyymmdd_hhnn”) & “_backup.accdb”

Dim FolderPath As String
FolderPath = Me.txtフォルダパス.Value

Dim BU As Boolean
BU = BackUpFile(FolderPath, FileName)
If Not BU Then
Exit Sub
End If

Dim UpdateTime As String
UpdateTime = Format(Now, “yyyy/mm/dd_hh:nn”)


Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = CurrentProject.Connection
Set rs = New ADODB.Recordset
rs.Open “tbバックアップ履歴”, cn, adOpenKeyset, adLockOptimistic
Dim I As Long, j As Long, k As String, No As String
I = rs.RecordCount
I = Nz(I, “0”)
For j = 1 To 8
k = k + “0”
Next j
I = I + 1

No = Format(CInt(I), k)
With rs
.Fields(0).Value = No
.Fields(1).Value = UpdateTime
.Fields(2).Value = FileName
End With
MsgBox “バックアップデータの更新履歴を追加しました。”

Exit Sub

MsgBox Err.Description
Resume err_Exit:

End Sub

Private Sub 更新ボタン_Click()
Me.バックアップ履歴リスト.RowSource = “tbバックアップ履歴”
End Sub
Private Sub 参照ボタン_Click()
Me.txtフォルダパス.Value = FDFolderPicker

End Sub


You may also like...

Your email will not be published. Name and Email fields are required