Currently this code takes data from my Access database and exports it to a premade Excel file. It will close the file if it is open to allow it to properly transfer all the data, it then reopens it for the user to view the new data and graphs. As it stands that is all working fine.
What I would like the file to do is always be set to read-only so that the users can modify the data however they want and save it to their own file without me having to worry about the data being written over on the original. I had the code simply set the file to read only when it was done updating and to normal when it needed to be updated, but someone can modify that by simply clicking the file and unmarking the check box, so that wont work.
I have now set the file to require a password to modify, which effectively makes it read only without any chance of someone changing the file without knowing the password or deleting the file. The problem I am running into is that I cannot find a way to automate password entry when the first getobject is initiated to allow for data transfer, then when the second object is initiated to reinstate the password.
Thanks for any help you can give.
'Open Excel and Create a graph based on data subform
Private Sub CmdExcel_Click()
Dim objExcel As Object
Dim strFile As String
Dim objCount As Integer
strFile = "C:\File.xls"
objCount = [All subform].Form.RecordsetClone.RecordCount
'Checks to see if there are greater than 50 records and asks user if they would like to import all the data to excel if it is
If objCount > 50 Then
Select Case MsgBox("You are about to send a large amount of data to the excel file. The current graphs may not provide a proper view of the data if it is too large. Do you wish to transfer the data anyway?", vbExclamation + vbYesNo, "Caution")
Case vbYes
'code continues as normal
Case vbNo
GoTo Last 'skips the rest of the code so user can choose a new set of data
End Select
End If
'Grabs excel file saves it then closes it and changes it from read only so that data can be imported even if the file is open
Set objExcel = GetObject(strFile)
objExcel.Application.Visible = False
objExcel.Windows(1).Visible = False
objExcel.Close SaveChanges:=False
Set objExcel = Nothing
SetAttr "C:\File.xls", vbNormal
Data is transferred in at this point using a few transfer spreadsheet functions based on criteria on my Access form
'open the excel file for viewing
Set objExcel = GetObject(strFile)
objExcel.RefreshAll
objExcel.Application.Visible = True
objExcel.Windows(1).Visible = True
What I would like the file to do is always be set to read-only so that the users can modify the data however they want and save it to their own file without me having to worry about the data being written over on the original. I had the code simply set the file to read only when it was done updating and to normal when it needed to be updated, but someone can modify that by simply clicking the file and unmarking the check box, so that wont work.
I have now set the file to require a password to modify, which effectively makes it read only without any chance of someone changing the file without knowing the password or deleting the file. The problem I am running into is that I cannot find a way to automate password entry when the first getobject is initiated to allow for data transfer, then when the second object is initiated to reinstate the password.
Thanks for any help you can give.
'Open Excel and Create a graph based on data subform
Private Sub CmdExcel_Click()
Dim objExcel As Object
Dim strFile As String
Dim objCount As Integer
strFile = "C:\File.xls"
objCount = [All subform].Form.RecordsetClone.RecordCount
'Checks to see if there are greater than 50 records and asks user if they would like to import all the data to excel if it is
If objCount > 50 Then
Select Case MsgBox("You are about to send a large amount of data to the excel file. The current graphs may not provide a proper view of the data if it is too large. Do you wish to transfer the data anyway?", vbExclamation + vbYesNo, "Caution")
Case vbYes
'code continues as normal
Case vbNo
GoTo Last 'skips the rest of the code so user can choose a new set of data
End Select
End If
'Grabs excel file saves it then closes it and changes it from read only so that data can be imported even if the file is open
Set objExcel = GetObject(strFile)
objExcel.Application.Visible = False
objExcel.Windows(1).Visible = False
objExcel.Close SaveChanges:=False
Set objExcel = Nothing
SetAttr "C:\File.xls", vbNormal
Data is transferred in at this point using a few transfer spreadsheet functions based on criteria on my Access form
'open the excel file for viewing
Set objExcel = GetObject(strFile)
objExcel.RefreshAll
objExcel.Application.Visible = True
objExcel.Windows(1).Visible = True