Advertisement

07.09.2008 at 09:08AM PDT, ID: 23550815
[x]
Attachment Details

How would you cause Excel to generate only 1 customized message box asking the user whether or not to save an Excel file ?

Asked by zimmer9 in Microsoft ADP, Microsoft Excel Spreadsheet Software, Access Coding/Macros

I am developing an Access 2003 application using Access as the front end and SQL Server as the back end database using an ADP file. I use the DoCmd.Transferspreadsheet command to transfer an Access table to Excel.

In the Attached Code snippet, I display ALL the code behind my Access interface. The user simply clicks on a button to execute a stored procedure and the RESULT SET gets populated into an Access table.
Then the DoCmd.Transferspreadsheet command exports the Access table to an Excel file. In the ATTACHED CODE SNIPPET is a subroutine titled StartDocLexNex that generates a Message Box asking the user "Do you want to save the file ?".

After the user views the Excel file and attempts to close the file, Excel automatically asks the following question in the form of a Message Box:

Do you want to save the changes you made to 'REDFLAG...XLS' ?   YES   NO   CANCEL

If the USER answers "NO", the subroutine will DELETE the Excel file. This routine works fine but I would like to prevent the following Message Box generated automatically by Excel from displaying:

Do you want to save the changes you made to 'REDFLAG...XLS' ?   YES   NO   CANCEL

and instead use my own MESSAGE BOX which would display the following question:

"Do you want to save the file   YES    NO ?"

Do you know how to prevent this 1st message box generated automatilcally as follows:

"Do want to save the changes you made to 'REDFLAG...XLS' ?   YES   NO   CANCEL"

from displaying ?

Currently I get 2 Message Boxes in the following order:
1) Do you want to save the changes you made to 'REDFLAG...XLS' ?   YES   NO   CANCEL

2) Do you want to save the file   YES    NO

I just want to display a message box "Do you want to save the file" which is hardcoded in the subroutine
titled StartDocLexNex.
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
Option Explicit
Public footnote As String
Dim clsMonitor As CExcelMonitor
Private Const strAccessPath0 = "\\AbandonedProperty\UDL\Access\"
Private Const strAccessPath16 = "TA1099Reports\"
Dim intYearSP As Integer
Dim strScreenType As String
 
Private Sub Command852_Click()
    Dim cn As ADODB.Recordset
    Dim ExportedFile As String
    Dim rstQueryFS As ADODB.Recordset
    Dim objXL As Excel.Application
    Dim objWS As Excel.Worksheet
    Dim fld As ADODB.Field
    Dim com As ADODB.Command
    
    txtDateFrom1099.Value = "01/01/2008"
    txtDateTo1099.Value = "06/30/2008"
                   
    Set cn = New ADODB.Recordset
    strScreenType = "A1099"
        
    cn.ActiveConnection = CurrentProject.Connection
    cn.CursorType = adOpenStatic
    cn.CursorLocation = adUseServer
    cn.LockType = adLockReadOnly
               
    DoCmd.Hourglass True
    Set com = New ADODB.Command
    With com
       .CommandType = adCmdStoredProc
       .CommandText = "dbo.procA1099RedFlag"
       .Parameters.Append .CreateParameter("DteFrom", adDate, adParamInput, , CDate(txtDateFrom1099.Value))
       .Parameters.Append .CreateParameter("DteTo", adDate, adParamInput, , CDate(txtDateTo1099.Value))
       .ActiveConnection = CurrentProject.Connection
       Set rstQueryFS = .Execute
    End With
    
    ExportedFile = strAccessPath0 & strAccessPath16 & "REDFLAG" & "_" & intYearSP & "_" & Format(Now, "mmddhhnnss") & ".XLS"
    
    footnote = "This file represents extraction of unique Account Numbers."
    
    DoCmd.TransferSpreadsheet acExport, 8, "dbo.tblA1099RedFlag", ExportedFile, True, ""
    
    MsgBox "Red Flag records have been exported to Excel", vbOKOnly, ""
    
    If isFileExist(ExportedFile) Then StartDocLexNex ExportedFile, footnote, strScreenType, txtDateFrom1099.Value, txtDateTo1099.Value
    
    DoCmd.Hourglass False
End Sub
 
Private Sub Form_Load()
    Dim filename As String
    Dim cn As ADODB.Recordset
              
    DoCmd.Maximize
               
    Set cn = New ADODB.Recordset
  
    cn.ActiveConnection = CurrentProject.Connection
    cn.CursorType = adOpenStatic
    cn.CursorLocation = adUseServer
    cn.LockType = adLockReadOnly
End Sub
 
Private Sub StartDocLexNex(filename, footnote, strScreenType, txtDateFrom, txtDateTo)
    Dim xlApp As Excel.Application
    Dim xlWB As Excel.Workbook
    Dim xlWS As Excel.Worksheet
 
    Dim intRows As Long
 
    Set xlApp = CreateObject("excel.application")
 
    xlApp.Workbooks.Open (filename)
 
    xlApp.Visible = True
    Set xlWS = xlApp.ActiveWorkbook.Worksheets(1)
    xlWS.Columns.AutoFit
 
    intRows = xlWS.UsedRange.Rows.count
 
    xlWS.Cells(intRows + 5, 1).Value = footnote
 
    xlWS.Cells(intRows + 6, 1).Value = "For the period " & txtDateFrom & " To " & txtDateTo
    xlApp.ScreenUpdating = True
 
    If (MsgBox("Do you want to save the file", vbYesNo)) = vbYes Then
        For Each xlWB In xlApp.Workbooks
            xlWB.Save
        Next xlWB
    End If
 
    With xlApp
        .ScreenUpdating = True
        .DisplayAlerts = 0
        .Workbooks.Close
        .DisplayAlerts = 1
        .Quit
    End With
 
    Set xlWS = Nothing
    Set xlWB = Nothing
    Set xlApp = Nothing
 
    Kill filename
End Sub
 
Private Function isFileExist(filePath As String) As Boolean
    isFileExist = (filePath <> "" And Dir$(filePath) <> "")
End Function
[+][-]07.09.2008 at 09:14AM PDT, ID: 21965349

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.09.2008 at 09:29AM PDT, ID: 21965523

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.09.2008 at 09:59AM PDT, ID: 21965839

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.21.2008 at 10:04AM PDT, ID: 22052261

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.21.2008 at 10:13AM PDT, ID: 22052333

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft ADP, Microsoft Excel Spreadsheet Software, Access Coding/Macros
Sign Up Now!
Solution Provided By: zorvek
Participating Experts: 1
Solution Grade: A
 
 
[+][-]07.21.2008 at 12:03PM PDT, ID: 22053377

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.21.2008 at 12:08PM PDT, ID: 22053419

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628