473,796 Members | 2,619 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Autostore Password for Export from Access query to excel spreadsheet.

20 New Member
Hi All,

I have finally succeeded in exporting to a preformated excel spreadsheet.
I have one tiny setback.

One of the sheets I am exporting to must be password protected.

When I do this and export I am prompted for the password.

This defeats the point.

Is there a way in access to autostore the password for an excel spreadsheet so that everytime it is exported the password is automatically passed to excel.

Thanks in Advance
May 21 '07 #1
7 4955
ADezii
8,834 Recognized Expert Expert
Hi All,

I have finally succeeded in exporting to a preformated excel spreadsheet.
I have one tiny setback.

One of the sheets I am exporting to must be password protected.

When I do this and export I am prompted for the password.

This defeats the point.

Is there a way in access to autostore the password for an excel spreadsheet so that everytime it is exported the password is automatically passed to excel.

Thanks in Advance
Are you using the TransferSpreads heet Method for your Export? If so, there is no built-in provision for passing the Worksheet Password in the process.
May 22 '07 #2
tasmontique
20 New Member
I am exporting from a query in vba. I am not using transfer spreadsheet
May 24 '07 #3
ADezii
8,834 Recognized Expert Expert
I am exporting from a query in vba. I am not using transfer spreadsheet
Post the code you are using to Export.
May 24 '07 #4
tasmontique
20 New Member
Here is the code below that I use to export to access.

Private Sub CreateMonthlyRe port(rsschedule srecords As DAO.Recordset, curday As String)

Dim excelapp As New Excel.Applicati on
Dim excelfile As New Excel.Workbook
Dim excelsheet As New Excel.Worksheet
Dim savefilepath As String
Dim tempi As Integer

Set excelfile = excelapp.Workbo oks.Open(Curren tProject.Path & "Template1.xls" )
Set excelsheet = excelfile.Works heets.Item(1)

excelsheet.Cell s(4, 1) = "EFFECTIVE Fr:" & Format(txtStart Date, "mmmm-dd,YYYY") & _
"To:" & Format(txtEndDa te, "mmmm-dd,YYYY")

excelsheet.Cell s(5, 7) = DateTime.Now
excelsheet.Rang e("L13") = DateTime.Now

If Not (rsschedulesrec ords.EOF) Then
tempi = 1
While Not rsschedulesreco rds.EOF
excelsheet.Rang e("A9", "L9").Inser t
excelsheet.Cell s(9, 1) = tempi
excelsheet.Cell s(9, 2) = Format(rsschedu lesrecords.Fiel ds(3).Value, "dd-mmm-yy")
excelsheet.Cell s(9, 3) = Format(rsschedu lesrecords.Fiel ds(4).Value, "dd-mmm-yy")
excelsheet.Cell s(9, 4) = curday
excelsheet.Cell s(9, 5) = rsschedulesreco rds.Fields(1).V alue
excelsheet.Cell s(9, 6) = rsschedulesreco rds.Fields(2).V alue
excelsheet.Cell s(9, 7) = rsschedulesreco rds.Fields(17). Value
excelsheet.Cell s(9, 8) = rsschedulesreco rds.Fields(20). Value
excelsheet.Cell s(9, 9) = CStr(rsschedule srecords.Fields (19).Value) & " - " & _
CStr(rsschedule srecords.Fields (22).Value)
excelsheet.Cell s(9, 10) = rsschedulesreco rds.Fields(23). Value
excelsheet.Cell s(9, 11) = rsschedulesreco rds.Fields(24). Value
excelsheet.Cell s(9, 12) = rsschedulesreco rds.Fields(28). Value
rsschedulesreco rds.MoveNext
tempi = tempi + 1
Wend
End If

savefilepath = "\" & curday & "_Report_On-" & CStr(Format(Dat eTime.Now, "dd_mmm_yyy y-hh_mm_ss")) & ".xls"
excelfile.SaveA s CurrentProject. Path & savefilepath

excelapp.Active Workbook.Close True, CurrentProject. Path & savefilepath
excelapp.Quit

Set excelsheet = Nothing
Set excelfile = Nothing
Set excelapp = Nothing

End Sub

Here is the query I perform before exporting
Private Sub cmdExport_Click ()
On Error GoTo FinalStep

Dim querystring As String
Dim dbase As DAO.Database
Dim rsSchedules As DAO.Recordset
Dim tempi As Integer
Dim rptcnt As Integer
rptcnt = 0


querystring = GetQueryString
If (Len(Trim(query string)) > 0) Then
Set dbase = CurrentDb
If (Me.Optgroup.Va lue = OptMonthly.Opti onValue) Then
MsgBox "Exporting monthly report for " & CStr(txtStartDa te.Value) & _
" to " & CStr(txtEndDate .Value), vbExclamation, "Export"
tempi = 1

While tempi < 8
querystring = querystring & " AND " & GetWeekDay(temp i) & " = Yes "
Set rsSchedules = dbase.OpenRecor dset(querystrin g)
If Not (rsSchedules.EO F = True) Then
CreateMonthlyRe port rsSchedules, GetWeekDay(temp i)
rptcnt = rptcnt + 1
End If
rsSchedules.Clo se
tempi = tempi + 1
Wend
'I have ommitted some code here that applies to other reports

dbase.Close
If (rptcnt = 0) Then
MsgBox "No Repords Found for Excel Export", vbExclamation, "Export"
Else
MsgBox "Export to excel file(s) completed", vbExclamation, "Export Complete"
End If
Set rsSchedules = Nothing
Set dbase = Nothing
End If

I use the above code to export to excel. Initially Template1 was not password protected but when I password protected the template. I am prompted for a password right before MsgBox "Export To Excel completed" This defeats the point because I want the user to be able to export the information but only individuals with the password to open it.

Thanks helping.
May 25 '07 #5
ADezii
8,834 Recognized Expert Expert
Here is the code below that I use to export to access.

Private Sub CreateMonthlyRe port(rsschedule srecords As DAO.Recordset, curday As String)

Dim excelapp As New Excel.Applicati on
Dim excelfile As New Excel.Workbook
Dim excelsheet As New Excel.Worksheet
Dim savefilepath As String
Dim tempi As Integer

Set excelfile = excelapp.Workbo oks.Open(Curren tProject.Path & "Template1.xls" )
Set excelsheet = excelfile.Works heets.Item(1)

excelsheet.Cell s(4, 1) = "EFFECTIVE Fr:" & Format(txtStart Date, "mmmm-dd,YYYY") & _
"To:" & Format(txtEndDa te, "mmmm-dd,YYYY")

excelsheet.Cell s(5, 7) = DateTime.Now
excelsheet.Rang e("L13") = DateTime.Now

If Not (rsschedulesrec ords.EOF) Then
tempi = 1
While Not rsschedulesreco rds.EOF
excelsheet.Rang e("A9", "L9").Inser t
excelsheet.Cell s(9, 1) = tempi
excelsheet.Cell s(9, 2) = Format(rsschedu lesrecords.Fiel ds(3).Value, "dd-mmm-yy")
excelsheet.Cell s(9, 3) = Format(rsschedu lesrecords.Fiel ds(4).Value, "dd-mmm-yy")
excelsheet.Cell s(9, 4) = curday
excelsheet.Cell s(9, 5) = rsschedulesreco rds.Fields(1).V alue
excelsheet.Cell s(9, 6) = rsschedulesreco rds.Fields(2).V alue
excelsheet.Cell s(9, 7) = rsschedulesreco rds.Fields(17). Value
excelsheet.Cell s(9, 8) = rsschedulesreco rds.Fields(20). Value
excelsheet.Cell s(9, 9) = CStr(rsschedule srecords.Fields (19).Value) & " - " & _
CStr(rsschedule srecords.Fields (22).Value)
excelsheet.Cell s(9, 10) = rsschedulesreco rds.Fields(23). Value
excelsheet.Cell s(9, 11) = rsschedulesreco rds.Fields(24). Value
excelsheet.Cell s(9, 12) = rsschedulesreco rds.Fields(28). Value
rsschedulesreco rds.MoveNext
tempi = tempi + 1
Wend
End If

savefilepath = "\" & curday & "_Report_On-" & CStr(Format(Dat eTime.Now, "dd_mmm_yyy y-hh_mm_ss")) & ".xls"
excelfile.SaveA s CurrentProject. Path & savefilepath

excelapp.Active Workbook.Close True, CurrentProject. Path & savefilepath
excelapp.Quit

Set excelsheet = Nothing
Set excelfile = Nothing
Set excelapp = Nothing

End Sub

Here is the query I perform before exporting
Private Sub cmdExport_Click ()
On Error GoTo FinalStep

Dim querystring As String
Dim dbase As DAO.Database
Dim rsSchedules As DAO.Recordset
Dim tempi As Integer
Dim rptcnt As Integer
rptcnt = 0


querystring = GetQueryString
If (Len(Trim(query string)) > 0) Then
Set dbase = CurrentDb
If (Me.Optgroup.Va lue = OptMonthly.Opti onValue) Then
MsgBox "Exporting monthly report for " & CStr(txtStartDa te.Value) & _
" to " & CStr(txtEndDate .Value), vbExclamation, "Export"
tempi = 1

While tempi < 8
querystring = querystring & " AND " & GetWeekDay(temp i) & " = Yes "
Set rsSchedules = dbase.OpenRecor dset(querystrin g)
If Not (rsSchedules.EO F = True) Then
CreateMonthlyRe port rsSchedules, GetWeekDay(temp i)
rptcnt = rptcnt + 1
End If
rsSchedules.Clo se
tempi = tempi + 1
Wend
'I have ommitted some code here that applies to other reports

dbase.Close
If (rptcnt = 0) Then
MsgBox "No Repords Found for Excel Export", vbExclamation, "Export"
Else
MsgBox "Export to excel file(s) completed", vbExclamation, "Export Complete"
End If
Set rsSchedules = Nothing
Set dbase = Nothing
End If

I use the above code to export to excel. Initially Template1 was not password protected but when I password protected the template. I am prompted for a password right before MsgBox "Export To Excel completed" This defeats the point because I want the user to be able to export the information but only individuals with the password to open it.

Thanks helping.
I am working on your dilemma, but as of yet have not come up with a viable solution. Be patient - I'll keep on trying.
May 26 '07 #6
tasmontique
20 New Member
I am working on your dilemma, but as of yet have not come up with a viable solution. Be patient - I'll keep on trying.
Thanks For Your Effort.
May 31 '07 #7
ADezii
8,834 Recognized Expert Expert
Thanks For Your Effort.
The answer is so simple that it actually eluded me but here you go. Insert lines 13 and 44 exactly where indicated in your code. Lines 12 and 43 are Comments and are not necessary, though it may be a good idea to keep them in place. Let me know how you make out.
Expand|Select|Wrap|Line Numbers
  1. Private Sub CreateMonthlyReport(rsschedulesrecords As DAO.Recordset, curday As String)
  2.  
  3. Dim excelapp As New Excel.Application
  4. Dim excelfile As New Excel.Workbook
  5. Dim excelsheet As New Excel.Worksheet
  6. Dim savefilepath As String
  7. Dim tempi As Integer
  8.  
  9. Set excelfile = excelapp.Workbooks.Open(CurrentProject.Path & "Template1.xls")
  10. Set excelsheet = excelfile.Worksheets.Item(1)
  11.  
  12. 'To UNPROTECT the Worksheet prior to writing data
  13. excelsheet.Unprotect Password:= "password in quotes"
  14.  
  15. excelsheet.Cells(4, 1) = "EFFECTIVE Fr:" & Format(txtStartDate, "mmmm-dd,YYYY") & _
  16. "To:" & Format(txtEndDate, "mmmm-dd,YYYY")
  17.  
  18. excelsheet.Cells(5, 7) = DateTime.Now
  19. excelsheet.Range("L13") = DateTime.Now
  20.  
  21. If Not (rsschedulesrecords.EOF) Then
  22.   tempi = 1
  23.     While Not rsschedulesrecords.EOF
  24.       excelsheet.Range("A9", "L9").Insert
  25.       excelsheet.Cells(9, 1) = tempi
  26.       excelsheet.Cells(9, 2) = Format(rsschedulesrecords.Fields(3).Value, "dd-mmm-yy")
  27.       excelsheet.Cells(9, 3) = Format(rsschedulesrecords.Fields(4).Value, "dd-mmm-yy")
  28.       excelsheet.Cells(9, 4) = curday
  29.       excelsheet.Cells(9, 5) = rsschedulesrecords.Fields(1).Value
  30.       excelsheet.Cells(9, 6) = rsschedulesrecords.Fields(2).Value
  31.       excelsheet.Cells(9, 7) = rsschedulesrecords.Fields(17).Value
  32.       excelsheet.Cells(9, 8) = rsschedulesrecords.Fields(20).Value
  33.       excelsheet.Cells(9, 9) = CStr(rsschedulesrecords.Fields(19).Value) & " - " & _
  34. CStr(rsschedulesrecords.Fields(22).Value)
  35.       excelsheet.Cells(9, 10) = rsschedulesrecords.Fields(23).Value
  36.       excelsheet.Cells(9, 11) = rsschedulesrecords.Fields(24).Value
  37.       excelsheet.Cells(9, 12) = rsschedulesrecords.Fields(28).Value
  38.       rsschedulesrecords.MoveNext
  39.          tempi = tempi + 1
  40.     Wend
  41. End If
  42.  
  43. 'To RE-PROTECT the Worksheet after writing data but before Save
  44. excelsheet.Protect Password:= "password in quotes"
  45.  
  46. savefilepath = "\" & curday & "_Report_On-" & CStr(Format(DateTime.Now, "dd_mmm_yyyy-hh_mm_ss")) & ".xls"
  47. excelfile.SaveAs CurrentProject.Path & savefilepath
  48.  
  49. excelapp.ActiveWorkbook.Close True, CurrentProject.Path & savefilepath
  50. excelapp.Quit
  51.  
  52. Set excelsheet = Nothing
  53. Set excelfile = Nothing
  54. Set excelapp = Nothing
  55.  
  56. End Sub
May 31 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
14792
by: Paolo | last post by:
Friends, I need help with some code to export different tables to a single spreadsheet in Excel. My excel file is named REPORT and the spreadsheet is named CLIENTS. I do have the code to export a single table to Excel but have problems with multimple tables. Thanks.
4
3133
by: Gary Wright | last post by:
I have an Access 2K database split into front and back. Quite often the users want to do some data analysis that I have not created a report for so they want to export some subset of the data into and Excel spreadsheet. Since the data often comes from many different tables, I have decided to create a temporary Access table, put all the data into it then use the Docmd.TransferSpreadsheet command to output the table to a spreadsheet. In...
3
2714
by: MissiMaths | last post by:
I have used outputTo to export a copy of a table out of access into excel. I was wondering if there is anyway to set a password on this within the code so that it is read only in .xls format? I was also hoping that there might be a away of importing a password protected excel file into a table in access where the password is known. I have searched help and can't see anything and also I couldn't find the answer here as yet. I hope someone...
3
11933
by: John | last post by:
Is there a way to code the button that's available in the query window--microsoft excel icon that exports to excel. I know transferspreadsheet will do this---but I want the query, which is in a pivot table view, to be exported as a pivot, not just a data list. Does this code exist? Is it transferspreadsheet but with a twist?
1
2298
by: Ellen Manning | last post by:
I'm trying to export an Excel2K spreadsheet to A2K. Here is a sample of the Excel spreadsheet: LastName FirstName Hours Location HoursPercent Doe John 9 WMC 2.94 VA Med Ctr 265 VA 86.60 32 VA Res Clinic 10.45 <blank row>
3
3050
by: excyauseme | last post by:
Hi guys! Do you know what is the best way to export a text file, this one is a log file that is already comma delimited thru a module run by my access database, to an excel spreadsheet? I need to do this thru the module, and I don't see how I can export a txt file from access without loading it to a temp table first. I've checked out the DoCmd.TransferText methods, where you have to have a table or query or schema ini first, and the...
0
1289
by: Simp33 | last post by:
Is want to know is there anyway to attain the name of a table or the name of a query when you are exporting from access to excel. I want to be able to display the name of the access table/query that the spreadsheet came from on a separate worksheet of the spreadsheet. This is needed b/c i export hundreds of files a month and should a problem occur with a report, i want to be able to look at the info that is stored on the second worksheet of...
1
9779
by: smaczylo | last post by:
Hello, I've recently been asked to work with Microsoft Access, and while I feel quite comfortable with Excel, I'm at a complete loss with databases. If someone could help me with this issue I'm having I'd be most appreciative. The database is already constructed, I'm just wanting to export the data to an excel file. In short, I'm hoping to export two Tables (or queries...not sure which to use - they both seem to have the same data) in...
5
5774
by: cdun2 | last post by:
Hello, I'm a non_VBA coder who has been asked to update the following Function: ************************** Function EMAILER_REV_BY_ACCTCODE_MACRO() On Error GoTo RA_EMAILER_Err DoCmd.SetWarnings False
0
9533
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10461
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10239
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10019
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7555
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6796
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.