activate button after another button clicked

honnour

Registered User.
Local time
Today, 12:47
Joined
Mar 1, 2012
Messages
43
Hello everybody,

I have a form with 4 buttons.
What I want to do is, at startup I want only the first button is active.
After clicking the first button second button will activate and without clicking first two, user can not click the third button.

How can I do that?

Thank you
 
First, on your Form design click on the 2nd button and set its Enabled property to False, similarly the 3rd and 4th. And then you will be able to see the buttons greyed, so on the 1st button OnClick() method simple enable the second, similarly 2nd_OnClick() and 3rd_OnClick().. Goes something like..
Code:
Private Sub 1st_OnClick()
2nd.Enabled = True
End Sub
 
First, on your Form design click on the 2nd button and set its Enabled property to False, similarly the 3rd and 4th. And then you will be able to see the buttons greyed, so on the 1st button OnClick() method simple enable the second, similarly 2nd_OnClick() and 3rd_OnClick().. Goes something like..
Code:
Private Sub 1st_OnClick()
2nd.Enabled = True
End Sub

thank you,

but now when I clicked it says "object required"
 
okay.. the names I have given is only an example.. it should be the name of the button followed by enabled=true.. Say if your button name is NameBtn.. then..

NameBtn.Enabled = True

When it says object requiered.. It means that the one you have provided is invalid/not present on the form.
 
okay.. the names I have given is only an example.. it should be the name of the button followed by enabled=true.. Say if your button name is NameBtn.. then..

NameBtn.Enabled = True

When it says object requiered.. It means that the one you have provided is invalid/not present on the form.
Thank you mate
 
Hi, I'm looking at doing the same thing here, except the button I need to press before the Close button can be selected has this in the 'On Click' option:
=InitializeBackUp()

=InitializeBackUp() refers to this code:
Code:
Option Compare Database
Option Explicit
Public strWinZipPath As String
Function InitializeBackUp()
Dim strErrMsg As String
Dim strErrTitle As String
Dim strMsg As String
strErrMsg = "  BackUp Action cancelled. Database not backed up.            "
strErrTitle = " BackUp Cancelled"
strMsg = "WinZip has been found. The Database will be compressed and saved as a WinZip file.    "
DoCmd.OpenForm "Filenames", , , , , acHidden
If IsNull(Forms!FileNames.BackUpFrom) Or Forms!FileNames.BackUpFrom = "" Then
      MsgBox "  No Data File selected. Database not backed up.            ", vbCritical, " Dean's Software"
      Exit Function
End If
If IsNull(Forms!FileNames.BackUpTo) Or Forms!FileNames.BackUpTo = "" Then
      MsgBox "  No Destination Directory selected. Database not backed up.            ", vbCritical, " Dean'sr Software"
      Exit Function
End If
'Find Winzip
If Dir("C:\Program Files\WinZip\WinZip32.exe", vbDirectory) <> "" Then  'WinXP
    If MsgBox(strMsg, vbInformation + vbOKCancel, " Commencing BackUp") = vbOK Then
        strWinZipPath = "C:\Program Files\WinZip\WinZip32.exe"
        Call ZipandBackUpDb
    Else
        MsgBox strErrMsg, vbCritical, strErrTitle
    End If
 
Else
    If MsgBox("WinZip cannot be Located. The Database will be saved as a copy.       ", vbInformation + vbOKCancel, " Commencing BackUp") = vbOK Then
        Call BackUpDb
    Else
        MsgBox strErrMsg, vbCritical, strErrTitle
    End If
End If
DoCmd.Close acForm, "FileNames"
End Function
Function ZipandBackUpDb()   'WinZip Found
On Error GoTo Err_BackUpDb
 
Dim fso, fl 'Add line Alastair 69 (08/02/2006)
Dim sSourcePath As String
Dim sSourceFile As String
Dim sBackupPath As String
Dim sBackupFile As String
Dim strFileName As String
Dim sBackupFolder As String
Dim sFinalPath As String
Dim sFilePart As String
Dim strError As String
    strFileName = Forms!FileNames.BackUpFrom
    sSourcePath = strFileName
If Not Dir("C:\Temp", vbDirectory) <> "" Then MkDir "C:\Temp"
sBackupPath = "C:\Temp\"
'Get the final part of the file
sFilePart = ParseFileName(sSourcePath, 1)
sFilePart = strReplace(sFilePart, " ", "_")
sBackupFile = sFilePart
    sBackupFolder = Forms!FileNames.BackUpTo
    sFinalPath = sBackupFolder & "\"
Screen.MousePointer = 11
Set fso = CreateObject("Scripting.FileSystemObject") 'Add line Alastair 69 (11/02/2006)
fso.CopyFile sSourcePath, sBackupPath & sBackupFile, True
Set fso = Nothing
Dim sWinZip As String
Dim sZipFile As String
Dim sZipFileName As String
Dim sFileToZip As String
sWinZip = strWinZipPath 'Location of the WinZip program
sZipFileName = Left(sBackupFile, InStr(1, sBackupFile, ".", vbTextCompare) - 1) & "_" & Format(Date, "dd-mm-yyyy") & "-" & Format(Time, "hh-mmAMPM") & ".zip"
sZipFile = sBackupPath & sZipFileName
sFileToZip = sBackupPath & sBackupFile
Call Shell(sWinZip & " -a " & sZipFile & " " & sFileToZip, vbHide)
Call RunProgMeter
'Set fso = New filesystemobject
Set fso = CreateObject("Scripting.FileSystemObject") 'Add line Alastair 69 (08/02/2006)
fso.CopyFile sBackupPath & sZipFileName, sFinalPath & sZipFileName, True
Set fso = Nothing
Screen.MousePointer = 0
MsgBox "Backup was successful. " & "The backup file is named:       " & Chr(13) & "     " & sFinalPath & sZipFileName, vbInformation, "Backup Completed"
If Dir(sBackupPath & sBackupFile) <> "" Then Kill (sBackupPath & sBackupFile)
If Dir(sBackupPath & sZipFileName) <> "" Then Kill (sBackupPath & sZipFileName)
Exit_BackUpDb:
    Exit Function
 
Err_BackUpDb:
    Select Case Err.Number
    Case 5
        strError = "Disk is full! Can not move the zip file to the Drive. Please move the " & sZipFile & " file to a safe location."
        If Dir(sBackupPath & sBackupFile) <> "" Then Kill (sBackupPath & sBackupFile)
        If Dir(sBackupPath & sZipFileName) <> "" Then Kill (sBackupPath & sZipFileName)
    Case 53
        strError = "Disk is full! Can not move the zip file to the Drive. Please move the " & sZipFile & " file to a safe location."
 
    Case 71
        If Dir(sZipFile) <> "" Then Kill sZipFile
        If Dir(sFileToZip) <> "" Then Kill sFileToZip
        strError = "There is no diskette in the Drive.        "
 
    Case -2147024784
        strError = "File is to large to be zipped to the Drive!" & vbNewLine & sZipFile
 
    Case Else
        strError = Err.Description
 
    End Select
        MsgBox Err.Number & " - " & strError, vbCritical, " BackUp Error"
        Screen.MousePointer = 0
        Resume Exit_BackUpDb
 
End Function
Function BackUpDb() 'No WinZip
On Error GoTo Err_BackUpDb
Dim fso, fl 'Add line Alastair 69 (08/02/2006)
Dim sSourcePath As String
Dim sBackupPath As String
Dim sBackupFile As String
Dim strFileName As String
Dim sBackupFolder As String
Dim sFilePart As String
Dim sFileExtension As String
 
    strFileName = Forms!FileNames.BackUpFrom
    sSourcePath = strFileName
'Establish the file name to allow the same name to be used
sFilePart = ParseFileName(sSourcePath, 2)
'Establish the extension and make the copy the same. (*.mdb stays *.mdb,*.mde stays *.mde etc)
sFileExtension = ParseFileName(sSourcePath, 3)
    sBackupFolder = Forms!FileNames.BackUpTo
    sBackupPath = sBackupFolder & "\"
sBackupFile = sFilePart & "_" & Format(Date, "dd-mm-yyyy") & "-" & Format(Time, "hh-mmAMPM") & sFileExtension
Screen.MousePointer = 11
Call RunProgMeter
Screen.MousePointer = 0
Set fso = CreateObject("Scripting.FileSystemObject") 'Add line Alastair 69 (08/02/2006)
fso.CopyFile sSourcePath, sBackupPath & sBackupFile, True
Set fso = Nothing
MsgBox "BackUp Complete. Backup file is located at " & sBackupPath & sBackupFile, vbInformation, " DCA Expro BackUp"
Exit_BackUpDb:
    Exit Function
Err_BackUpDb:
    MsgBox Err.Number & " - " & Err.Description, vbCritical, " BackUp Failure"
    Resume Exit_BackUpDb
End Function
Function FindBackUpFile()
Dim strPath As String
Dim InitDir As String
CDSearchString = MakeFilterString("Database Files (*.mdb;*.adp;*.mdw;*.mda;*.mde)", "*.mdb;*.adp;*.mdw;*.mda;*.mde", "All Files (*.*)", "*.*")
CDCaption = "Select Database File to Back Up..."
 
    strPath = LaunchCD
 
    If Not strPath = "None Selected" Then
      FindBackUpFile = strPath
    Else
      FindBackUpFile = "None Selected"
    End If
End Function
Function FindBackUpFolder()
Dim strFolderName As String
strFolderName = BrowseFolder("Select Folder to BackUp to")
If IsNull(strFolderName) Or strFolderName = "" Then
    FindBackUpFolder = "None Selected"
Else
    FindBackUpFolder = strFolderName
End If
End Function
Private Function ParseFileName(sfPath As String, Optional iRet As Long)
On Error GoTo ParseFileName_Err
    Dim sFullName As String
    Dim sFilePathOnly As String
    Dim sDrive As String
    Dim sPath As String
    Dim sLocation As String
    Dim sFilename As String
    Dim sShortName As String
    Dim sExt As String
 
    sFullName = sfPath
 
    ' Find the final "\" in the path.
    sPath = sFullName
 
    Do While Right$(sPath, 1) <> "\"
    sPath = Left$(sPath, Len(sPath) - 1)
    Loop
 
    ' Find the Drive.
    sDrive = Left$(sFullName, InStr(sFullName, ":") + 1)
    'tbDrive = sDrive
 
    ' Find the Location.
    sLocation = Mid$(sPath, Len(sDrive) - 2)
    'tbLocation = sLocation
 
    ' Find the Path.
    sPath = Mid$(sPath, Len(sDrive) + 1)
    'tbPath = sPath
    ' Find the file name.
    sFilename = Mid$(sFullName, Len(sPath) + 4)
 
    Select Case iRet
    Case 1
        sFilename = Mid$(sFullName, Len(sPath) + 4)
        ParseFileName = sFilename
    Case 2
        sShortName = Left$(sFilename, Len(sFilename) - 4)
        ParseFileName = sShortName
    Case 3
        sExt = Right$(sFilename, 4)
        ParseFileName = sExt
    End Select
ParseFileName_Exit:
    Exit Function
ParseFileName_Err:
    MsgBox Err.Number & " - " & Err.Description
    Resume ParseFileName_Exit
End Function
Function strReplace(sMainString As String, _
sSubString As String, strReplaceString As String) As String
'* Recursive function to replace all occurences of sSubString
'* with strReplaceString in sMainString
Dim I As Integer
Dim ipos As Integer
Dim S As String
Dim s1 As String, s2 As String
S = sMainString
ipos = InStr(1, sMainString, sSubString)
If ipos = 0 Then
    GoTo Exit_strReplace
End If
s1 = Mid(sMainString, 1, ipos - 1)
s2 = Mid(sMainString, ipos + Len(sSubString), Len(sMainString))
S = s1 & strReplaceString & _
    strReplace(s2, sSubString, strReplaceString)
Exit_strReplace:
    strReplace = S
End Function
Function RunProgMeter()
Dim mwth As Long
Dim mstep As Long
mstep = 0
mwth = Forms!backup!Box7.Width
Forms!backup!Box7.Visible = True
Forms!backup!Box8.Width = 0
Forms!backup!Box8.Visible = True
Do Until mstep >= mwth
    Forms!backup!Box8.Width = mstep
    mstep = mstep + 2
DoEvents
Loop
Forms!backup!Box8.Visible = False
Forms!backup!Box7.Visible = False
End Function

So, what and where should I put into this Initialize code to make the 'Close' button disabled until the 'Back Up Now' button has been pressed.
Or....if possible, disable the close button until the progress meter has been completed.

My purpose for this is I am creating this database for my Program, Self Contained Breathing Apparatus, in the Fire Department. It is the most important extra duty program in the department and I will likely have 60+ people browsing the database, So I would like to force a backup upon login just in case they manage to screw something up. :eek: :banghead::banghead:

Thanks :D
 
Hi I am not completely sure, as I am unable to view your code or your message on its entirety (as I am checking it through my mobile phone) . From what I understand you have to make the close button to default disabled through the form's design and then place the enabled property at the very last line, to true inside the back up on click method..
 
That is correct. Im just unsure how or where to start the code off.

Disabling the CloseButton on the back up form I can do. Enabling the CloseButton on the back up form from the basBackUp module after slecting the BackUpNowButton is where i have my trouble.
 

Users who are viewing this thread

Back
Top Bottom