Close Form only...please

JRT2006

Registered User.
Local time
Today, 15:29
Joined
Jul 6, 2012
Messages
36
Hello All, I'm taken an old code from an application at work and added it to a project I'm working on. The problem I have run into is this; the open form has a 'tab control' using buttons rather then tabs. the last button is an Exit button, when pressed, the prompt opens with the normal yes/no quit question. When you select yes, it completely closes down access. I'd like to get it to only close that form.

I've done a lot of browsing and tried manythings with no success.
I am using Access 2007
Here is the code for the menu change (change when each button is clicked)

Code:
Private Sub Menu_Change()
 
    Dim tbc As Control, pge As Page
    Dim ctl As Control
    Dim intCommand As Integer
 
    ' Return reference to tab control.
    Set tbc = Me!Menu
    ' Return reference to currently selected page.
    Set pge = tbc.Pages(tbc.Value)
    ' Enumerate controls on currently selected page.
    'Debug.Print pge.Name & " Controls:"
    If pge.Name = "Page1" Then
        Me.Filter = "[ItemNumber] = 0 AND [SwitchboardID]=" & 1
    ElseIf pge.Name = "Page2" Then
        Me.Filter = "[ItemNumber] = 0 AND [SwitchboardID]=" & 2
    ElseIf pge.Name = "Page3" Then
        Me.Filter = "[ItemNumber] = 0 AND [SwitchboardID]=" & 5
    ElseIf pge.Name = "Page4" Then
        Me.Filter = "[ItemNumber] = 0 AND [SwitchboardID]=" & 6
    ElseIf pge.Name = "Page5" Then
        Me.Filter = "[ItemNumber] = 0 AND [SwitchboardID]=" & 7
    ElseIf pge.Name = "Page6" Then
        intCommand = MsgBox("Are you sure you want to Exit?", vbInformation + vbYesNo, "Close Inventory Program?")
        If intCommand = vbYes Then
            Quit
        Else
            Me.Page1.SetFocus
        End If
    End If
End Sub

much Thanks for any solution!
 
Change Quit to

DoCmd.Close

with the appropriate arguments.
 
Change Quit to

DoCmd.Close

with the appropriate arguments.

Brilliant. Such a simple solution looked over...thank you
 
No problem, and welcome to the site!
 
Thanks a bunch. I'll probably be picking through quite often here as I'm a beginner and "self-teaching" as i go along.

Always wanted to learn and now that I've started I'm spending 12+ hours a day messing with all of it
 
I've decided to force the option of backing up the database on users who open it. I've imported a BackUp Systems database onto my own and it runs at startup right after a user logs in.

Thing is, the back up screen has two buttons to click, one is Back Up Now and the other is Close. If they hit Close, they can bypass the backup and continue, not what I want since there could be 60+ people browsing through this.
What I would like is to have the Close button hidden, or not selectable until the backup is finished. Then, when the complete the backup and hit the Close button, it should take them to the main Screen.

This.....I hate to say....I have absolutely no clue how to do, or if its even possible.

I'm not sure what code you would need to provide help so I will post what I think is important and if anything else is needed let me know.

The 'On Click' for the Back Up button has listed
=InitializeBackUp()

The 'On Click' Close Button has listed
Code:
Private Sub Close_Click()
On Error GoTo Err_Close_Click

    DoCmd.Close
Exit_Close_Click:
    Exit Sub
Err_Close_Click:
    MsgBox Err.Description
    Resume Exit_Close_Click
End Sub

There is a basBackUp 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

Thanks again
 
Last edited:
Change Quit to

Code:
DoCmd.Close
with the appropriate arguments.

Personally I have been using:

Code:
  'Close window "self"
  DoCmd.Close acForm, Me.Name
 
Sorry, missed the follow-up question. Why not simply delete the close button, and add that line to the end of the backup routine?
 

Users who are viewing this thread

Back
Top Bottom