Marshall Brooks
Member
- Local time
- Yesterday, 22:47
- Joined
- Feb 28, 2023
- Messages
- 727
This code was derived from https://www.access-programmers.co.uk/forums/threads/f11-disable-or-not.328822/
The code works flawlessly if I step through it line by line.
I'm looking at the lines in red:
The code works fine with the 40-second pause inserted (usually), but I hate to wait 40 seconds if a 1-second pause would sometimes be sufficient.
Q1 - The loop was supposed to work so that the script paused until the dummy.accdb file was created and then allowed the script to continue. It does not work and I'm not sure why.
Q2 - If the loop did work, in the CopyFile statement failed completely, the script would never exit, so I would like some method (timer on the form), to exit the loop after some interval (45 seconds, 60 seconds, etc.)
Q3 - Not related to this, but this is for a button on a form. If I had module code and wanted a similar timer function, how would I call that?
Thanks in advance!!!
The code works flawlessly if I step through it line by line.
I'm looking at the lines in red:
Code:
Private Sub btnACCDE_Click()
' https://www.access-programmers.co.uk/forums/threads/f11-disable-or-not.328822/
Dim CurrentDBPath, DummyPath As String, OutPath As String
Dim objFSO As Object
On Error GoTo ErrHandler
strResult = Dialog.Box(Prompt:="Did you do a Decompile and Compact and Repair?\n\nClicking No will cancel .ACCDE File creation." & "", Buttons:=(4 + 32))
If strResult = vbNo Then
'MsgBox "I'm Done"
Exit Sub
End If
Screen.MousePointer = 11
CurrentDb.Properties("AllowSpecialKeys").value = False
'save and compile all modules - https://isladogs.co.uk/compile-modules/index.html
Application.SysCmd 504, 16483
CurrentDBPath = CurrentProject.Path & "\" & CurrentProject.Name
DummyPath = CurrentProject.Path & "\" & "Dummy.accdb"
' We need to make a copy of the db for the accde vba code to work. Will not work on current DB
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile CurrentDBPath, DummyPath
OutPath = Replace(CurrentDBPath, "accdb", "accde")
Pause (40)
Do Until Not Dir(DummyPath) = ""
DoEvents
Loop
Call MakeACCDE(DummyPath, OutPath)
objFSO.DeleteFile DummyPath
Screen.MousePointer = 1
If Dir(OutPath) = "" Then
Box "Something went wrong! ACCDE file was not created."
Else
Box "ACCDE created as " & OutPath & vbCrLf & "Check Date and Time"
End If
CurrentDb.Properties("AllowSpecialKeys").value = True
ExitSub:
Set objFSO = Nothing
Err_Exit:
Exit Sub
ErrHandler:
MsgBox "Error " & Err.Number & " " & Err.DESCRIPTION
Resume ExitSub
End Sub
The code works fine with the 40-second pause inserted (usually), but I hate to wait 40 seconds if a 1-second pause would sometimes be sufficient.
Q1 - The loop was supposed to work so that the script paused until the dummy.accdb file was created and then allowed the script to continue. It does not work and I'm not sure why.
Q2 - If the loop did work, in the CopyFile statement failed completely, the script would never exit, so I would like some method (timer on the form), to exit the loop after some interval (45 seconds, 60 seconds, etc.)
Q3 - Not related to this, but this is for a button on a form. If I had module code and wanted a similar timer function, how would I call that?
Thanks in advance!!!
Last edited: