If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Cannot get code to work for API Save Dialog Box
I have an access database (2000) where I want the user to click on a button
to save the current form (with subform) to excel. This event will open a dialog box so the user will be able to save. I have seen several links to http://www.mvps.org/access/api/api0001.htm when creating dialog box to save. However, I cannot get this code to work. What am I doing wrong? I copied the code exactly like shown on the website and then started making my changes to make it work. I did not understand how to put in my own coding, if this should be a substitute for testit or my own "on click" or function. Here is what I did by deleting the function testit(): Private Sub cmdTest_Click() Dim strFilter As String Dim strSaveFileName As String strFilter = ahtAddFilterItem(mystrFilter, "Excel Files (*.xls)", "*.xls") strSaveFileName = ahtCommonFileOpenSave(OpenFile:=False, Filter:=strFilter, Flags:=ahtOFN_OVERWRITEPROMPT Or ahtOFN_READONLY) End Sub I keep getting the error message: "only comments may appear after end sub, end function or end property." |
#2
|
|||
|
|||
Cannot get code to work for API Save Dialog Box
First, don't put anything in the module you downloaded. It could cause
problems. Here is an example of how I use that exact same API module: 'Set filter to show only Excel spreadsheets strfilter = ahtAddFilterItem(strfilter, "Excel Files (*.xls)") 'Hides the Read Only Check Box on the Dialog box lngFlags = ahtOFN_HIDEREADONLY strCurrMonth = Me.cboPeriod.Column(1) strCurrYear = Me.txtCurrYear 'Get the File Name To Save strDefaultDir = "\\rsltx1-bm01\busmgmt\Vought " & strCurrYear & "\" & strCurrYear _ & " Actuals\" & strCurrMonth & "\" varGetFileName = "Vought Invoice " & strCurrMonth & " " & strCurrYear & ".xls" varGetFileName = ahtCommonFileOpenSave(ahtOFN_OVERWRITEPROMPT, _ strDefaultDir, "Excel Spreadsheets (*.xls) *.xls", , _ "xls", varGetFileName, "Import Adjusted Actuals", , True) Me.Repaint If varGetFileName = "" Then 'User Clicked CANCEL GoTo LoadAdjustedActuals_Exit End If "Elleve" wrote: I have an access database (2000) where I want the user to click on a button to save the current form (with subform) to excel. This event will open a dialog box so the user will be able to save. I have seen several links to http://www.mvps.org/access/api/api0001.htm when creating dialog box to save. However, I cannot get this code to work. What am I doing wrong? I copied the code exactly like shown on the website and then started making my changes to make it work. I did not understand how to put in my own coding, if this should be a substitute for testit or my own "on click" or function. Here is what I did by deleting the function testit(): Private Sub cmdTest_Click() Dim strFilter As String Dim strSaveFileName As String strFilter = ahtAddFilterItem(mystrFilter, "Excel Files (*.xls)", "*.xls") strSaveFileName = ahtCommonFileOpenSave(OpenFile:=False, Filter:=strFilter, Flags:=ahtOFN_OVERWRITEPROMPT Or ahtOFN_READONLY) End Sub I keep getting the error message: "only comments may appear after end sub, end function or end property." |
#3
|
|||
|
|||
Cannot get code to work for API Save Dialog Box
Will I have to include the comboboxes in the coding? For your information,
the listbox I mentioned last time consist of two columns that are contain a relationship from a separate query. They are neccessary in order to pick up the correct information. This is done by =[Forms]![frmSupportScheduleMain]![List54].[column](0). Why can't I just export what is at the current form to excel since this information is already specified? Also, as for the coding you provided me - where exactly do I input this? Under the click event? Will I still need to keep the downloaded coding from the website as is or make changes to it. I apologize if I ask stupid questions, but that coding just got me lost. "Klatuu" wrote: First, don't put anything in the module you downloaded. It could cause problems. Here is an example of how I use that exact same API module: 'Set filter to show only Excel spreadsheets strfilter = ahtAddFilterItem(strfilter, "Excel Files (*.xls)") 'Hides the Read Only Check Box on the Dialog box lngFlags = ahtOFN_HIDEREADONLY strCurrMonth = Me.cboPeriod.Column(1) strCurrYear = Me.txtCurrYear 'Get the File Name To Save strDefaultDir = "\\rsltx1-bm01\busmgmt\Vought " & strCurrYear & "\" & strCurrYear _ & " Actuals\" & strCurrMonth & "\" varGetFileName = "Vought Invoice " & strCurrMonth & " " & strCurrYear & ".xls" varGetFileName = ahtCommonFileOpenSave(ahtOFN_OVERWRITEPROMPT, _ strDefaultDir, "Excel Spreadsheets (*.xls) *.xls", , _ "xls", varGetFileName, "Import Adjusted Actuals", , True) Me.Repaint If varGetFileName = "" Then 'User Clicked CANCEL GoTo LoadAdjustedActuals_Exit End If "Elleve" wrote: I have an access database (2000) where I want the user to click on a button to save the current form (with subform) to excel. This event will open a dialog box so the user will be able to save. I have seen several links to http://www.mvps.org/access/api/api0001.htm when creating dialog box to save. However, I cannot get this code to work. What am I doing wrong? I copied the code exactly like shown on the website and then started making my changes to make it work. I did not understand how to put in my own coding, if this should be a substitute for testit or my own "on click" or function. Here is what I did by deleting the function testit(): Private Sub cmdTest_Click() Dim strFilter As String Dim strSaveFileName As String strFilter = ahtAddFilterItem(mystrFilter, "Excel Files (*.xls)", "*.xls") strSaveFileName = ahtCommonFileOpenSave(OpenFile:=False, Filter:=strFilter, Flags:=ahtOFN_OVERWRITEPROMPT Or ahtOFN_READONLY) End Sub I keep getting the error message: "only comments may appear after end sub, end function or end property." |
#4
|
|||
|
|||
Cannot get code to work for API Save Dialog Box
Not stupid questions at all. See answers below in your post:
"Elleve" wrote: Will I have to include the comboboxes in the coding? For your information, No, what I sent was just an example. You can change it as necessary to use the values you need for your situation. If they come from a list box, just reference the column in the list box you need to use. the listbox I mentioned last time consist of two columns that are contain a relationship from a separate query. They are neccessary in order to pick up the correct information. This is done by =[Forms]![frmSupportScheduleMain]![List54].[column](0). Why can't I just export what is at the current form to excel since this information is already specified? You can. This code does not do the export, it only returns a path and file where you want to open or save the data. If you are exporting to Excel, you would use varGetFileName as the File argument in your TransferSpreadsheet. Also, as for the coding you provided me - where exactly do I input this? Under the click event? Will I still need to keep the downloaded coding from If you want this to happen as the result of a click event, then that would be the place to put it. You still need the downloaded code. It should be kept by itself in a Standard module. Mine is named modCommonDialog. The sample I provided calles the API routines in modCommonDialog. the website as is or make changes to it. I apologize if I ask stupid Do Not make changes to it. Calling APIs is very powerful, but also somewhat dangerous. If you make changes in the downloaded code, you could get some very weird unexpected results. API stands for Application Program Interface. What you are doing is making calls to DLL's in the Windows operating system. If you pass bad values, bad things can happen. Don't let this discourage you. The alternative is an ActiveX control. ActiveX controls are not that easy to deal with. This API is very useful. My current application uses it about 20 different places. questions, but that coding just got me lost. "Klatuu" wrote: First, don't put anything in the module you downloaded. It could cause problems. Here is an example of how I use that exact same API module: 'Set filter to show only Excel spreadsheets strfilter = ahtAddFilterItem(strfilter, "Excel Files (*.xls)") 'Hides the Read Only Check Box on the Dialog box lngFlags = ahtOFN_HIDEREADONLY strCurrMonth = Me.cboPeriod.Column(1) strCurrYear = Me.txtCurrYear 'Get the File Name To Save strDefaultDir = "\\rsltx1-bm01\busmgmt\Vought " & strCurrYear & "\" & strCurrYear _ & " Actuals\" & strCurrMonth & "\" varGetFileName = "Vought Invoice " & strCurrMonth & " " & strCurrYear & ".xls" varGetFileName = ahtCommonFileOpenSave(ahtOFN_OVERWRITEPROMPT, _ strDefaultDir, "Excel Spreadsheets (*.xls) *.xls", , _ "xls", varGetFileName, "Import Adjusted Actuals", , True) Me.Repaint If varGetFileName = "" Then 'User Clicked CANCEL GoTo LoadAdjustedActuals_Exit End If "Elleve" wrote: I have an access database (2000) where I want the user to click on a button to save the current form (with subform) to excel. This event will open a dialog box so the user will be able to save. I have seen several links to http://www.mvps.org/access/api/api0001.htm when creating dialog box to save. However, I cannot get this code to work. What am I doing wrong? I copied the code exactly like shown on the website and then started making my changes to make it work. I did not understand how to put in my own coding, if this should be a substitute for testit or my own "on click" or function. Here is what I did by deleting the function testit(): Private Sub cmdTest_Click() Dim strFilter As String Dim strSaveFileName As String strFilter = ahtAddFilterItem(mystrFilter, "Excel Files (*.xls)", "*.xls") strSaveFileName = ahtCommonFileOpenSave(OpenFile:=False, Filter:=strFilter, Flags:=ahtOFN_OVERWRITEPROMPT Or ahtOFN_READONLY) End Sub I keep getting the error message: "only comments may appear after end sub, end function or end property." |
#5
|
|||
|
|||
Cannot get code to work for API Save Dialog Box
You're great in your feedback and speediness. I seem to be on the right
track now, I only have one more question regarding modules as I have never used them before - how do you set up the module? Is it like private sub-end sub? By the way, here is the code I have for the event itself: Private Sub cmdExportSupportSchedule_Click() 'Set filter to show only Excel spreadsheets strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.xls)") 'Hides the Read Only Check Box on the Dialog box lngFlags = ahtOFN_HIDEREADONLY 'Get the File Name To Save strDefaultDir = "c:/" varGetFileName = ahtCommonFileOpenSave(ahtOFN_OVERWRITEPROMPT, strDefaultDir, "Excel Spreadsheets (*.xls) *.xls", , "xls", varGetFileName, "Import Adjusted Actuals", , True) Me.Repaint If varGetFileName = "" Then 'User Clicked CANCEL GoTo LoadAdjustedActuals_Exit End If DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "frmSupportScheduleGLMainForm", varGetFileName, True End Sub Does this look like it would work? "Klatuu" wrote: Not stupid questions at all. See answers below in your post: "Elleve" wrote: Will I have to include the comboboxes in the coding? For your information, No, what I sent was just an example. You can change it as necessary to use the values you need for your situation. If they come from a list box, just reference the column in the list box you need to use. the listbox I mentioned last time consist of two columns that are contain a relationship from a separate query. They are neccessary in order to pick up the correct information. This is done by =[Forms]![frmSupportScheduleMain]![List54].[column](0). Why can't I just export what is at the current form to excel since this information is already specified? You can. This code does not do the export, it only returns a path and file where you want to open or save the data. If you are exporting to Excel, you would use varGetFileName as the File argument in your TransferSpreadsheet. Also, as for the coding you provided me - where exactly do I input this? Under the click event? Will I still need to keep the downloaded coding from If you want this to happen as the result of a click event, then that would be the place to put it. You still need the downloaded code. It should be kept by itself in a Standard module. Mine is named modCommonDialog. The sample I provided calles the API routines in modCommonDialog. the website as is or make changes to it. I apologize if I ask stupid Do Not make changes to it. Calling APIs is very powerful, but also somewhat dangerous. If you make changes in the downloaded code, you could get some very weird unexpected results. API stands for Application Program Interface. What you are doing is making calls to DLL's in the Windows operating system. If you pass bad values, bad things can happen. Don't let this discourage you. The alternative is an ActiveX control. ActiveX controls are not that easy to deal with. This API is very useful. My current application uses it about 20 different places. questions, but that coding just got me lost. "Klatuu" wrote: First, don't put anything in the module you downloaded. It could cause problems. Here is an example of how I use that exact same API module: 'Set filter to show only Excel spreadsheets strfilter = ahtAddFilterItem(strfilter, "Excel Files (*.xls)") 'Hides the Read Only Check Box on the Dialog box lngFlags = ahtOFN_HIDEREADONLY strCurrMonth = Me.cboPeriod.Column(1) strCurrYear = Me.txtCurrYear 'Get the File Name To Save strDefaultDir = "\\rsltx1-bm01\busmgmt\Vought " & strCurrYear & "\" & strCurrYear _ & " Actuals\" & strCurrMonth & "\" varGetFileName = "Vought Invoice " & strCurrMonth & " " & strCurrYear & ".xls" varGetFileName = ahtCommonFileOpenSave(ahtOFN_OVERWRITEPROMPT, _ strDefaultDir, "Excel Spreadsheets (*.xls) *.xls", , _ "xls", varGetFileName, "Import Adjusted Actuals", , True) Me.Repaint If varGetFileName = "" Then 'User Clicked CANCEL GoTo LoadAdjustedActuals_Exit End If "Elleve" wrote: I have an access database (2000) where I want the user to click on a button to save the current form (with subform) to excel. This event will open a dialog box so the user will be able to save. I have seen several links to http://www.mvps.org/access/api/api0001.htm when creating dialog box to save. However, I cannot get this code to work. What am I doing wrong? I copied the code exactly like shown on the website and then started making my changes to make it work. I did not understand how to put in my own coding, if this should be a substitute for testit or my own "on click" or function. Here is what I did by deleting the function testit(): Private Sub cmdTest_Click() Dim strFilter As String Dim strSaveFileName As String strFilter = ahtAddFilterItem(mystrFilter, "Excel Files (*.xls)", "*.xls") strSaveFileName = ahtCommonFileOpenSave(OpenFile:=False, Filter:=strFilter, Flags:=ahtOFN_OVERWRITEPROMPT Or ahtOFN_READONLY) End Sub I keep getting the error message: "only comments may appear after end sub, end function or end property." |
#6
|
|||
|
|||
Cannot get code to work for API Save Dialog Box
"Elleve" wrote: You're great in your feedback and speediness. I seem to be on the right track now, I only have one more question regarding modules as I have never used them before - how do you set up the module? Is it like private sub-end sub? By the way, here is the code I have for the event itself: Private Sub cmdExportSupportSchedule_Click() 'Set filter to show only Excel spreadsheets strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.xls)") 'Hides the Read Only Check Box on the Dialog box lngFlags = ahtOFN_HIDEREADONLY 'Get the File Name To Save strDefaultDir = "c:/" varGetFileName = ahtCommonFileOpenSave(ahtOFN_OVERWRITEPROMPT, strDefaultDir, "Excel Spreadsheets (*.xls) *.xls", , "xls", varGetFileName, "Import Adjusted Actuals", , True) Me.Repaint If varGetFileName = "" Then 'User Clicked CANCEL GoTo LoadAdjustedActuals_Exit End If DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "frmSupportScheduleGLMainForm", varGetFileName, True End Sub Does this look like it would work? "Klatuu" wrote: Not stupid questions at all. See answers below in your post: "Elleve" wrote: Will I have to include the comboboxes in the coding? For your information, No, what I sent was just an example. You can change it as necessary to use the values you need for your situation. If they come from a list box, just reference the column in the list box you need to use. the listbox I mentioned last time consist of two columns that are contain a relationship from a separate query. They are neccessary in order to pick up the correct information. This is done by =[Forms]![frmSupportScheduleMain]![List54].[column](0). Why can't I just export what is at the current form to excel since this information is already specified? You can. This code does not do the export, it only returns a path and file where you want to open or save the data. If you are exporting to Excel, you would use varGetFileName as the File argument in your TransferSpreadsheet. Also, as for the coding you provided me - where exactly do I input this? Under the click event? Will I still need to keep the downloaded coding from If you want this to happen as the result of a click event, then that would be the place to put it. You still need the downloaded code. It should be kept by itself in a Standard module. Mine is named modCommonDialog. The sample I provided calles the API routines in modCommonDialog. the website as is or make changes to it. I apologize if I ask stupid Do Not make changes to it. Calling APIs is very powerful, but also somewhat dangerous. If you make changes in the downloaded code, you could get some very weird unexpected results. API stands for Application Program Interface. What you are doing is making calls to DLL's in the Windows operating system. If you pass bad values, bad things can happen. Don't let this discourage you. The alternative is an ActiveX control. ActiveX controls are not that easy to deal with. This API is very useful. My current application uses it about 20 different places. questions, but that coding just got me lost. "Klatuu" wrote: First, don't put anything in the module you downloaded. It could cause problems. Here is an example of how I use that exact same API module: 'Set filter to show only Excel spreadsheets strfilter = ahtAddFilterItem(strfilter, "Excel Files (*.xls)") 'Hides the Read Only Check Box on the Dialog box lngFlags = ahtOFN_HIDEREADONLY strCurrMonth = Me.cboPeriod.Column(1) strCurrYear = Me.txtCurrYear 'Get the File Name To Save strDefaultDir = "\\rsltx1-bm01\busmgmt\Vought " & strCurrYear & "\" & strCurrYear _ & " Actuals\" & strCurrMonth & "\" varGetFileName = "Vought Invoice " & strCurrMonth & " " & strCurrYear & ".xls" varGetFileName = ahtCommonFileOpenSave(ahtOFN_OVERWRITEPROMPT, _ strDefaultDir, "Excel Spreadsheets (*.xls) *.xls", , _ "xls", varGetFileName, "Import Adjusted Actuals", , True) Me.Repaint If varGetFileName = "" Then 'User Clicked CANCEL GoTo LoadAdjustedActuals_Exit End If "Elleve" wrote: I have an access database (2000) where I want the user to click on a button to save the current form (with subform) to excel. This event will open a dialog box so the user will be able to save. I have seen several links to http://www.mvps.org/access/api/api0001.htm when creating dialog box to save. However, I cannot get this code to work. What am I doing wrong? I copied the code exactly like shown on the website and then started making my changes to make it work. I did not understand how to put in my own coding, if this should be a substitute for testit or my own "on click" or function. Here is what I did by deleting the function testit(): Private Sub cmdTest_Click() Dim strFilter As String Dim strSaveFileName As String strFilter = ahtAddFilterItem(mystrFilter, "Excel Files (*.xls)", "*.xls") strSaveFileName = ahtCommonFileOpenSave(OpenFile:=False, Filter:=strFilter, Flags:=ahtOFN_OVERWRITEPROMPT Or ahtOFN_READONLY) End Sub I keep getting the error message: "only comments may appear after end sub, end function or end property." |
#7
|
|||
|
|||
Cannot get code to work for API Save Dialog Box
First thing is, Private Sub End Sub is not a module, it is a procedure.
There are two types of procedures. A Sub is called to execute code but does not return any value to the calling procedure. You usually use a Sub for events or for tasks that may be called from more than one place. Basically, if you have a procedure you may call from more than one form or form multiple places in a form, you should put that code in a Sub. If it is called from more than one form or report, then it should be in a Standard module. If it is only used by one form, then it can go in the General section of the form module. A Function is another type of procedure. It is used to perform some evaluation or calculation and returns a value to the calling procedure. The same rules as for Subs applys on how to use it . A module is a collection of Subs and or Functions. Forms and reports can have, but are not required to have modules. The code you put in your form and report events are in the form or report module. A Standard module is a collection of code that is usually called from forms, reports, or other modules. For example, the code you downloaded for the API is a module. I usually group procedures into modules that have something in common. I have one module that is nothing more that date functions - Calculating the number of working days between two dates, Finding the Friday of a given week, etc. As to your code below. There are two things that need attention. First there is a problem with this line: DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "frmSupportScheduleGLMainForm", varGetFileName, True The next issue is declaring variables. Although not required, it is best to establish the habit of always declaring and typing your variables. You can always tell what data type my variables are by the prefix on the name. For example var is for a Variant data type, str is for a String data type, lng is Long Integer, etc. The reason you did not see the variable declarations the code I sent is because they were declared at the module level because I need them in more than this sub. Read up on varialbe Scoping. So, add these lines right after the Sub statement: Dim strFilter as String Dim lngFlags as Long Dim strDefaultDir as String Dim varGetFileName as Variant And, good luck! frmSupportScheduleGLMainForm is a form name. What you want here is the name of the table or query you are exporting. "Elleve" wrote: You're great in your feedback and speediness. I seem to be on the right track now, I only have one more question regarding modules as I have never used them before - how do you set up the module? Is it like private sub-end sub? By the way, here is the code I have for the event itself: Private Sub cmdExportSupportSchedule_Click() 'Set filter to show only Excel spreadsheets strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.xls)") 'Hides the Read Only Check Box on the Dialog box lngFlags = ahtOFN_HIDEREADONLY 'Get the File Name To Save strDefaultDir = "c:/" varGetFileName = ahtCommonFileOpenSave(ahtOFN_OVERWRITEPROMPT, strDefaultDir, "Excel Spreadsheets (*.xls) *.xls", , "xls", varGetFileName, "Import Adjusted Actuals", , True) Me.Repaint If varGetFileName = "" Then 'User Clicked CANCEL GoTo LoadAdjustedActuals_Exit End If DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "frmSupportScheduleGLMainForm", varGetFileName, True End Sub Does this look like it would work? "Klatuu" wrote: Not stupid questions at all. See answers below in your post: "Elleve" wrote: Will I have to include the comboboxes in the coding? For your information, No, what I sent was just an example. You can change it as necessary to use the values you need for your situation. If they come from a list box, just reference the column in the list box you need to use. the listbox I mentioned last time consist of two columns that are contain a relationship from a separate query. They are neccessary in order to pick up the correct information. This is done by =[Forms]![frmSupportScheduleMain]![List54].[column](0). Why can't I just export what is at the current form to excel since this information is already specified? You can. This code does not do the export, it only returns a path and file where you want to open or save the data. If you are exporting to Excel, you would use varGetFileName as the File argument in your TransferSpreadsheet. Also, as for the coding you provided me - where exactly do I input this? Under the click event? Will I still need to keep the downloaded coding from If you want this to happen as the result of a click event, then that would be the place to put it. You still need the downloaded code. It should be kept by itself in a Standard module. Mine is named modCommonDialog. The sample I provided calles the API routines in modCommonDialog. the website as is or make changes to it. I apologize if I ask stupid Do Not make changes to it. Calling APIs is very powerful, but also somewhat dangerous. If you make changes in the downloaded code, you could get some very weird unexpected results. API stands for Application Program Interface. What you are doing is making calls to DLL's in the Windows operating system. If you pass bad values, bad things can happen. Don't let this discourage you. The alternative is an ActiveX control. ActiveX controls are not that easy to deal with. This API is very useful. My current application uses it about 20 different places. questions, but that coding just got me lost. "Klatuu" wrote: First, don't put anything in the module you downloaded. It could cause problems. Here is an example of how I use that exact same API module: 'Set filter to show only Excel spreadsheets strfilter = ahtAddFilterItem(strfilter, "Excel Files (*.xls)") 'Hides the Read Only Check Box on the Dialog box lngFlags = ahtOFN_HIDEREADONLY strCurrMonth = Me.cboPeriod.Column(1) strCurrYear = Me.txtCurrYear 'Get the File Name To Save strDefaultDir = "\\rsltx1-bm01\busmgmt\Vought " & strCurrYear & "\" & strCurrYear _ & " Actuals\" & strCurrMonth & "\" varGetFileName = "Vought Invoice " & strCurrMonth & " " & strCurrYear & ".xls" varGetFileName = ahtCommonFileOpenSave(ahtOFN_OVERWRITEPROMPT, _ strDefaultDir, "Excel Spreadsheets (*.xls) *.xls", , _ "xls", varGetFileName, "Import Adjusted Actuals", , True) Me.Repaint If varGetFileName = "" Then 'User Clicked CANCEL GoTo LoadAdjustedActuals_Exit End If "Elleve" wrote: I have an access database (2000) where I want the user to click on a button to save the current form (with subform) to excel. This event will open a dialog box so the user will be able to save. I have seen several links to http://www.mvps.org/access/api/api0001.htm when creating dialog box to save. However, I cannot get this code to work. What am I doing wrong? I copied the code exactly like shown on the website and then started making my changes to make it work. I did not understand how to put in my own coding, if this should be a substitute for testit or my own "on click" or function. Here is what I did by deleting the function testit(): Private Sub cmdTest_Click() Dim strFilter As String Dim strSaveFileName As String strFilter = ahtAddFilterItem(mystrFilter, "Excel Files (*.xls)", "*.xls") strSaveFileName = ahtCommonFileOpenSave(OpenFile:=False, Filter:=strFilter, Flags:=ahtOFN_OVERWRITEPROMPT Or ahtOFN_READONLY) End Sub I keep getting the error message: "only comments may appear after end sub, end function or end property." |
#8
|
|||
|
|||
Cannot get code to work for API Save Dialog Box
First, I got an error message for "GoTo LoadAdjustedActuals_Exit" so I used
this instead: If varGetFileName = "" Then 'User Clicked CANCEL Exit Sub End If Will this work or should I do something else? Second, after making this change I managed to open the dialog box, but not the correct one. The dialog box opening was to open a file, while I want to export/save. What changes should I do to make this happen? "Klatuu" wrote: First thing is, Private Sub End Sub is not a module, it is a procedure. There are two types of procedures. A Sub is called to execute code but does not return any value to the calling procedure. You usually use a Sub for events or for tasks that may be called from more than one place. Basically, if you have a procedure you may call from more than one form or form multiple places in a form, you should put that code in a Sub. If it is called from more than one form or report, then it should be in a Standard module. If it is only used by one form, then it can go in the General section of the form module. A Function is another type of procedure. It is used to perform some evaluation or calculation and returns a value to the calling procedure. The same rules as for Subs applys on how to use it . A module is a collection of Subs and or Functions. Forms and reports can have, but are not required to have modules. The code you put in your form and report events are in the form or report module. A Standard module is a collection of code that is usually called from forms, reports, or other modules. For example, the code you downloaded for the API is a module. I usually group procedures into modules that have something in common. I have one module that is nothing more that date functions - Calculating the number of working days between two dates, Finding the Friday of a given week, etc. As to your code below. There are two things that need attention. First there is a problem with this line: DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "frmSupportScheduleGLMainForm", varGetFileName, True The next issue is declaring variables. Although not required, it is best to establish the habit of always declaring and typing your variables. You can always tell what data type my variables are by the prefix on the name. For example var is for a Variant data type, str is for a String data type, lng is Long Integer, etc. The reason you did not see the variable declarations the code I sent is because they were declared at the module level because I need them in more than this sub. Read up on varialbe Scoping. So, add these lines right after the Sub statement: Dim strFilter as String Dim lngFlags as Long Dim strDefaultDir as String Dim varGetFileName as Variant And, good luck! frmSupportScheduleGLMainForm is a form name. What you want here is the name of the table or query you are exporting. "Elleve" wrote: You're great in your feedback and speediness. I seem to be on the right track now, I only have one more question regarding modules as I have never used them before - how do you set up the module? Is it like private sub-end sub? By the way, here is the code I have for the event itself: Private Sub cmdExportSupportSchedule_Click() 'Set filter to show only Excel spreadsheets strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.xls)") 'Hides the Read Only Check Box on the Dialog box lngFlags = ahtOFN_HIDEREADONLY 'Get the File Name To Save strDefaultDir = "c:/" varGetFileName = ahtCommonFileOpenSave(ahtOFN_OVERWRITEPROMPT, strDefaultDir, "Excel Spreadsheets (*.xls) *.xls", , "xls", varGetFileName, "Import Adjusted Actuals", , True) Me.Repaint If varGetFileName = "" Then 'User Clicked CANCEL GoTo LoadAdjustedActuals_Exit End If DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "frmSupportScheduleGLMainForm", varGetFileName, True End Sub Does this look like it would work? "Klatuu" wrote: Not stupid questions at all. See answers below in your post: "Elleve" wrote: Will I have to include the comboboxes in the coding? For your information, No, what I sent was just an example. You can change it as necessary to use the values you need for your situation. If they come from a list box, just reference the column in the list box you need to use. the listbox I mentioned last time consist of two columns that are contain a relationship from a separate query. They are neccessary in order to pick up the correct information. This is done by =[Forms]![frmSupportScheduleMain]![List54].[column](0). Why can't I just export what is at the current form to excel since this information is already specified? You can. This code does not do the export, it only returns a path and file where you want to open or save the data. If you are exporting to Excel, you would use varGetFileName as the File argument in your TransferSpreadsheet. Also, as for the coding you provided me - where exactly do I input this? Under the click event? Will I still need to keep the downloaded coding from If you want this to happen as the result of a click event, then that would be the place to put it. You still need the downloaded code. It should be kept by itself in a Standard module. Mine is named modCommonDialog. The sample I provided calles the API routines in modCommonDialog. the website as is or make changes to it. I apologize if I ask stupid Do Not make changes to it. Calling APIs is very powerful, but also somewhat dangerous. If you make changes in the downloaded code, you could get some very weird unexpected results. API stands for Application Program Interface. What you are doing is making calls to DLL's in the Windows operating system. If you pass bad values, bad things can happen. Don't let this discourage you. The alternative is an ActiveX control. ActiveX controls are not that easy to deal with. This API is very useful. My current application uses it about 20 different places. questions, but that coding just got me lost. "Klatuu" wrote: First, don't put anything in the module you downloaded. It could cause problems. Here is an example of how I use that exact same API module: 'Set filter to show only Excel spreadsheets strfilter = ahtAddFilterItem(strfilter, "Excel Files (*.xls)") 'Hides the Read Only Check Box on the Dialog box lngFlags = ahtOFN_HIDEREADONLY strCurrMonth = Me.cboPeriod.Column(1) strCurrYear = Me.txtCurrYear 'Get the File Name To Save strDefaultDir = "\\rsltx1-bm01\busmgmt\Vought " & strCurrYear & "\" & strCurrYear _ & " Actuals\" & strCurrMonth & "\" varGetFileName = "Vought Invoice " & strCurrMonth & " " & strCurrYear & ".xls" varGetFileName = ahtCommonFileOpenSave(ahtOFN_OVERWRITEPROMPT, _ strDefaultDir, "Excel Spreadsheets (*.xls) *.xls", , _ "xls", varGetFileName, "Import Adjusted Actuals", , True) Me.Repaint If varGetFileName = "" Then 'User Clicked CANCEL GoTo LoadAdjustedActuals_Exit End If "Elleve" wrote: I have an access database (2000) where I want the user to click on a button to save the current form (with subform) to excel. This event will open a dialog box so the user will be able to save. I have seen several links to http://www.mvps.org/access/api/api0001.htm when creating dialog box to save. However, I cannot get this code to work. What am I doing wrong? I copied the code exactly like shown on the website and then started making my changes to make it work. I did not understand how to put in my own coding, if this should be a substitute for testit or my own "on click" or function. Here is what I did by deleting the function testit(): Private Sub cmdTest_Click() Dim strFilter As String Dim strSaveFileName As String strFilter = ahtAddFilterItem(mystrFilter, "Excel Files (*.xls)", "*.xls") strSaveFileName = ahtCommonFileOpenSave(OpenFile:=False, Filter:=strFilter, Flags:=ahtOFN_OVERWRITEPROMPT Or ahtOFN_READONLY) End Sub I keep getting the error message: "only comments may appear after end sub, end function or end property." |
#9
|
|||
|
|||
Cannot get code to work for API Save Dialog Box
Sorry, I really sent the wrong code. Change th call to this:
varGetFileName = ahtCommonFileOpenSave( _ OpenFile:=False, _ InitialDir:=strDefaultDir, _ Filter:=strfilter, _ filename:=strDefaultFileName, _ Flags:=lngFlags, _ DialogTitle:="Save Report") OpenFile:=False will make it say "Save" instead of Open on the button DialogTitle:="Save Report" will make the Title bar say "Save Report" You can change it to whatever you want in your title bar. Your change it Exit Sub is fine. I did not notice that when I reviewed the code you sent earlier. So here is the whole thing with the changes above: Private Sub cmdExportSupportSchedule_Click() 'Set filter to show only Excel spreadsheets strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.xls)") 'Hides the Read Only Check Box on the Dialog box lngFlags = ahtOFN_HIDEREADONLY 'Get the File Name To Save strDefaultDir = "c:\" varGetFileName = ahtCommonFileOpenSave( _ OpenFile:=False, _ InitialDir:=strDefaultDir, _ Filter:=strfilter, _ filename:=strDefaultFileName, _ Flags:=lngFlags, _ DialogTitle:="Save Report") Me.Repaint If varGetFileName "" Then DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "TableOrQueryNameHere", varGetFileName, True End If "Elleve" wrote: First, I got an error message for "GoTo LoadAdjustedActuals_Exit" so I used this instead: If varGetFileName = "" Then 'User Clicked CANCEL Exit Sub End If Will this work or should I do something else? Second, after making this change I managed to open the dialog box, but not the correct one. The dialog box opening was to open a file, while I want to export/save. What changes should I do to make this happen? "Klatuu" wrote: First thing is, Private Sub End Sub is not a module, it is a procedure. There are two types of procedures. A Sub is called to execute code but does not return any value to the calling procedure. You usually use a Sub for events or for tasks that may be called from more than one place. Basically, if you have a procedure you may call from more than one form or form multiple places in a form, you should put that code in a Sub. If it is called from more than one form or report, then it should be in a Standard module. If it is only used by one form, then it can go in the General section of the form module. A Function is another type of procedure. It is used to perform some evaluation or calculation and returns a value to the calling procedure. The same rules as for Subs applys on how to use it . A module is a collection of Subs and or Functions. Forms and reports can have, but are not required to have modules. The code you put in your form and report events are in the form or report module. A Standard module is a collection of code that is usually called from forms, reports, or other modules. For example, the code you downloaded for the API is a module. I usually group procedures into modules that have something in common. I have one module that is nothing more that date functions - Calculating the number of working days between two dates, Finding the Friday of a given week, etc. As to your code below. There are two things that need attention. First there is a problem with this line: DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "frmSupportScheduleGLMainForm", varGetFileName, True The next issue is declaring variables. Although not required, it is best to establish the habit of always declaring and typing your variables. You can always tell what data type my variables are by the prefix on the name. For example var is for a Variant data type, str is for a String data type, lng is Long Integer, etc. The reason you did not see the variable declarations the code I sent is because they were declared at the module level because I need them in more than this sub. Read up on varialbe Scoping. So, add these lines right after the Sub statement: Dim strFilter as String Dim lngFlags as Long Dim strDefaultDir as String Dim varGetFileName as Variant And, good luck! frmSupportScheduleGLMainForm is a form name. What you want here is the name of the table or query you are exporting. "Elleve" wrote: You're great in your feedback and speediness. I seem to be on the right track now, I only have one more question regarding modules as I have never used them before - how do you set up the module? Is it like private sub-end sub? By the way, here is the code I have for the event itself: Private Sub cmdExportSupportSchedule_Click() 'Set filter to show only Excel spreadsheets strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.xls)") 'Hides the Read Only Check Box on the Dialog box lngFlags = ahtOFN_HIDEREADONLY 'Get the File Name To Save strDefaultDir = "c:/" varGetFileName = ahtCommonFileOpenSave(ahtOFN_OVERWRITEPROMPT, strDefaultDir, "Excel Spreadsheets (*.xls) *.xls", , "xls", varGetFileName, "Import Adjusted Actuals", , True) Me.Repaint If varGetFileName = "" Then 'User Clicked CANCEL GoTo LoadAdjustedActuals_Exit End If DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "frmSupportScheduleGLMainForm", varGetFileName, True End Sub Does this look like it would work? "Klatuu" wrote: Not stupid questions at all. See answers below in your post: "Elleve" wrote: Will I have to include the comboboxes in the coding? For your information, No, what I sent was just an example. You can change it as necessary to use the values you need for your situation. If they come from a list box, just reference the column in the list box you need to use. the listbox I mentioned last time consist of two columns that are contain a relationship from a separate query. They are neccessary in order to pick up the correct information. This is done by =[Forms]![frmSupportScheduleMain]![List54].[column](0). Why can't I just export what is at the current form to excel since this information is already specified? You can. This code does not do the export, it only returns a path and file where you want to open or save the data. If you are exporting to Excel, you would use varGetFileName as the File argument in your TransferSpreadsheet. Also, as for the coding you provided me - where exactly do I input this? Under the click event? Will I still need to keep the downloaded coding from If you want this to happen as the result of a click event, then that would be the place to put it. You still need the downloaded code. It should be kept by itself in a Standard module. Mine is named modCommonDialog. The sample I provided calles the API routines in modCommonDialog. the website as is or make changes to it. I apologize if I ask stupid Do Not make changes to it. Calling APIs is very powerful, but also somewhat dangerous. If you make changes in the downloaded code, you could get some very weird unexpected results. API stands for Application Program Interface. What you are doing is making calls to DLL's in the Windows operating system. If you pass bad values, bad things can happen. Don't let this discourage you. The alternative is an ActiveX control. ActiveX controls are not that easy to deal with. This API is very useful. My current application uses it about 20 different places. questions, but that coding just got me lost. "Klatuu" wrote: First, don't put anything in the module you downloaded. It could cause problems. Here is an example of how I use that exact same API module: 'Set filter to show only Excel spreadsheets strfilter = ahtAddFilterItem(strfilter, "Excel Files (*.xls)") 'Hides the Read Only Check Box on the Dialog box lngFlags = ahtOFN_HIDEREADONLY strCurrMonth = Me.cboPeriod.Column(1) strCurrYear = Me.txtCurrYear 'Get the File Name To Save strDefaultDir = "\\rsltx1-bm01\busmgmt\Vought " & strCurrYear & "\" & strCurrYear _ & " Actuals\" & strCurrMonth & "\" varGetFileName = "Vought Invoice " & strCurrMonth & " " & strCurrYear & ".xls" varGetFileName = ahtCommonFileOpenSave(ahtOFN_OVERWRITEPROMPT, _ strDefaultDir, "Excel Spreadsheets (*.xls) *.xls", , _ "xls", varGetFileName, "Import Adjusted Actuals", , True) Me.Repaint If varGetFileName = "" Then 'User Clicked CANCEL GoTo LoadAdjustedActuals_Exit End If "Elleve" wrote: I have an access database (2000) where I want the user to click on a button to save the current form (with subform) to excel. This event will open a dialog box so the user will be able to save. I have seen several links to http://www.mvps.org/access/api/api0001.htm when creating dialog box to save. However, I cannot get this code to work. What am I doing wrong? I copied the code exactly like shown on the website and then started making my changes to make it work. I did not understand how to put in my own coding, if this should be a substitute for testit or my own "on click" or function. Here is what I did by deleting the function testit(): Private Sub cmdTest_Click() Dim strFilter As String Dim strSaveFileName As String strFilter = ahtAddFilterItem(mystrFilter, "Excel Files (*.xls)", "*.xls") strSaveFileName = ahtCommonFileOpenSave(OpenFile:=False, Filter:=strFilter, Flags:=ahtOFN_OVERWRITEPROMPT Or ahtOFN_READONLY) End Sub I keep getting the error message: "only comments may appear after end sub, end function or end property." |
#10
|
|||
|
|||
Cannot get code to work for API Save Dialog Box
I managed to get the open dialog box by this code:
Private Sub cmdExportSupportSchedule_Click() Dim strFilter As String Dim lngFlags As Long Dim strDefaultDir As String Dim strSaveFileName As String 'Set filter to show only Excel spreadsheets strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.xls)", "*.xls") 'Hides the Read Only Check Box on the Dialog box lngFlags = ahtOFN_HIDEREADONLY 'Get the File Name To Save strSaveFileName = ahtCommonFileOpenSave(OpenFile:=False, Filter:=strFilter, Flags:=ahtOFN_OVERWRITEPROMPT Or ahtOFN_READONLY) If strSaveFileName = "" Then 'User Clicked CANCEL Exit Sub End If DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qrySubformUnionQuery1and2", strSaveFileName, True End Sub My problem now is that it is not exporting the correct information because it is taking information from the query only. I want it to export only what I have in the form w/subform currently. The main form is based on what is in the listbox and the subform is based on qrySupportScheduleUnionqry1and2 that is linked to the main form by four criterias of month, year, BU, and Affil. How do I get only the information selected? "Klatuu" wrote: First thing is, Private Sub End Sub is not a module, it is a procedure. There are two types of procedures. A Sub is called to execute code but does not return any value to the calling procedure. You usually use a Sub for events or for tasks that may be called from more than one place. Basically, if you have a procedure you may call from more than one form or form multiple places in a form, you should put that code in a Sub. If it is called from more than one form or report, then it should be in a Standard module. If it is only used by one form, then it can go in the General section of the form module. A Function is another type of procedure. It is used to perform some evaluation or calculation and returns a value to the calling procedure. The same rules as for Subs applys on how to use it . A module is a collection of Subs and or Functions. Forms and reports can have, but are not required to have modules. The code you put in your form and report events are in the form or report module. A Standard module is a collection of code that is usually called from forms, reports, or other modules. For example, the code you downloaded for the API is a module. I usually group procedures into modules that have something in common. I have one module that is nothing more that date functions - Calculating the number of working days between two dates, Finding the Friday of a given week, etc. As to your code below. There are two things that need attention. First there is a problem with this line: DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "frmSupportScheduleGLMainForm", varGetFileName, True The next issue is declaring variables. Although not required, it is best to establish the habit of always declaring and typing your variables. You can always tell what data type my variables are by the prefix on the name. For example var is for a Variant data type, str is for a String data type, lng is Long Integer, etc. The reason you did not see the variable declarations the code I sent is because they were declared at the module level because I need them in more than this sub. Read up on varialbe Scoping. So, add these lines right after the Sub statement: Dim strFilter as String Dim lngFlags as Long Dim strDefaultDir as String Dim varGetFileName as Variant And, good luck! frmSupportScheduleGLMainForm is a form name. What you want here is the name of the table or query you are exporting. "Elleve" wrote: You're great in your feedback and speediness. I seem to be on the right track now, I only have one more question regarding modules as I have never used them before - how do you set up the module? Is it like private sub-end sub? By the way, here is the code I have for the event itself: Private Sub cmdExportSupportSchedule_Click() 'Set filter to show only Excel spreadsheets strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.xls)") 'Hides the Read Only Check Box on the Dialog box lngFlags = ahtOFN_HIDEREADONLY 'Get the File Name To Save strDefaultDir = "c:/" varGetFileName = ahtCommonFileOpenSave(ahtOFN_OVERWRITEPROMPT, strDefaultDir, "Excel Spreadsheets (*.xls) *.xls", , "xls", varGetFileName, "Import Adjusted Actuals", , True) Me.Repaint If varGetFileName = "" Then 'User Clicked CANCEL GoTo LoadAdjustedActuals_Exit End If DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "frmSupportScheduleGLMainForm", varGetFileName, True End Sub Does this look like it would work? "Klatuu" wrote: Not stupid questions at all. See answers below in your post: "Elleve" wrote: Will I have to include the comboboxes in the coding? For your information, No, what I sent was just an example. You can change it as necessary to use the values you need for your situation. If they come from a list box, just reference the column in the list box you need to use. the listbox I mentioned last time consist of two columns that are contain a relationship from a separate query. They are neccessary in order to pick up the correct information. This is done by =[Forms]![frmSupportScheduleMain]![List54].[column](0). Why can't I just export what is at the current form to excel since this information is already specified? You can. This code does not do the export, it only returns a path and file where you want to open or save the data. If you are exporting to Excel, you would use varGetFileName as the File argument in your TransferSpreadsheet. Also, as for the coding you provided me - where exactly do I input this? Under the click event? Will I still need to keep the downloaded coding from If you want this to happen as the result of a click event, then that would be the place to put it. You still need the downloaded code. It should be kept by itself in a Standard module. Mine is named modCommonDialog. The sample I provided calles the API routines in modCommonDialog. the website as is or make changes to it. I apologize if I ask stupid Do Not make changes to it. Calling APIs is very powerful, but also somewhat dangerous. If you make changes in the downloaded code, you could get some very weird unexpected results. API stands for Application Program Interface. What you are doing is making calls to DLL's in the Windows operating system. If you pass bad values, bad things can happen. Don't let this discourage you. The alternative is an ActiveX control. ActiveX controls are not that easy to deal with. This API is very useful. My current application uses it about 20 different places. questions, but that coding just got me lost. "Klatuu" wrote: First, don't put anything in the module you downloaded. It could cause problems. Here is an example of how I use that exact same API module: 'Set filter to show only Excel spreadsheets strfilter = ahtAddFilterItem(strfilter, "Excel Files (*.xls)") 'Hides the Read Only Check Box on the Dialog box lngFlags = ahtOFN_HIDEREADONLY strCurrMonth = Me.cboPeriod.Column(1) strCurrYear = Me.txtCurrYear 'Get the File Name To Save strDefaultDir = "\\rsltx1-bm01\busmgmt\Vought " & strCurrYear & "\" & strCurrYear _ & " Actuals\" & strCurrMonth & "\" varGetFileName = "Vought Invoice " & strCurrMonth & " " & strCurrYear & ".xls" varGetFileName = ahtCommonFileOpenSave(ahtOFN_OVERWRITEPROMPT, _ strDefaultDir, "Excel Spreadsheets (*.xls) *.xls", , _ "xls", varGetFileName, "Import Adjusted Actuals", , True) Me.Repaint If varGetFileName = "" Then 'User Clicked CANCEL GoTo LoadAdjustedActuals_Exit End If "Elleve" wrote: I have an access database (2000) where I want the user to click on a button to save the current form (with subform) to excel. This event will open a dialog box so the user will be able to save. I have seen several links to http://www.mvps.org/access/api/api0001.htm when creating dialog box to save. However, I cannot get this code to work. What am I doing wrong? I copied the code exactly like shown on the website and then started making my changes to make it work. I did not understand how to put in my own coding, if this should be a substitute for testit or my own "on click" or function. Here is what I did by deleting the function testit(): Private Sub cmdTest_Click() Dim strFilter As String Dim strSaveFileName As String strFilter = ahtAddFilterItem(mystrFilter, "Excel Files (*.xls)", "*.xls") strSaveFileName = ahtCommonFileOpenSave(OpenFile:=False, Filter:=strFilter, Flags:=ahtOFN_OVERWRITEPROMPT Or ahtOFN_READONLY) End Sub I keep getting the error message: "only comments may appear after end sub, end function or end property." |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Visio Shortcuts | [email protected] | Visio | 1 | December 28th, 2006 11:28 PM |
Save work automatically | Ramon Niese | General Discussions | 2 | November 7th, 2005 04:59 PM |
Make Change Case in Excel a format rather than formula | Kevin | Worksheet Functions | 1 | March 18th, 2005 08:53 PM |
Open File and Save As don't work | David Evans | Powerpoint | 8 | June 4th, 2004 04:25 PM |
Two versions again-language issue | Otto | Setup, Installing & Configuration | 3 | May 28th, 2004 04:57 AM |