Hi all,
I can use some help with some code. I have an Access form that is displaying some data from an Excel Spreadsheet. My code, meaning the data I want to display is being displayed, but I need help to make my code better.
The spreadsheet has links to external data. How can I turn off the Excel message box asking "-To update all linked information, click Yes."? How can I turn off the message box asking me if i wish to open the spreadsheet "Read Only", if someone else has it open already?
Also, if you could, take a look at my code and tell me what I have left out? Do I need to close the spreadsheet in my code? etc;
This is one some of my first code, so I am sure I have made a ton of mistakes. Tell how bad it is, I can take it.
Thanks for the help,
James
Private Sub btnPopForm_Click()
Dim shift As String
Dim ExcelData As Integer
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet1 As Excel.Worksheet
Dim xlsheet2 As Excel.Worksheet
Dim xlsheet3 As Excel.Worksheet
Set xlapp = New Excel.Application
Set xlbook = xlapp.Workbooks.Open("r:\Palletizing Preshift Agenda.xls")
Set xlsheet1 = xlbook.Worksheets("1st Shift")
Set xlsheet2 = xlbook.Worksheets("2nd Shift")
Set xlsheet3 = xlbook.Worksheets("3rd Shift")
shift = Me.cmbShift.Value
If shift = "1st" Then
ExcelData = xlsheet1.range("E5")
ElseIf shift = "2nd" Then
ExcelData = xlsheet2.range("E5")
ElseIf shift = "3rd" Then
ExcelData = xlsheet3.range("E5")
ElseIf shift = "2nd" Then
ExcelData = 0
End If
Me.txtLinkData.Value = ExcelData
End Sub
I can use some help with some code. I have an Access form that is displaying some data from an Excel Spreadsheet. My code, meaning the data I want to display is being displayed, but I need help to make my code better.
The spreadsheet has links to external data. How can I turn off the Excel message box asking "-To update all linked information, click Yes."? How can I turn off the message box asking me if i wish to open the spreadsheet "Read Only", if someone else has it open already?
Also, if you could, take a look at my code and tell me what I have left out? Do I need to close the spreadsheet in my code? etc;
This is one some of my first code, so I am sure I have made a ton of mistakes. Tell how bad it is, I can take it.
Thanks for the help,
James
Private Sub btnPopForm_Click()
Dim shift As String
Dim ExcelData As Integer
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet1 As Excel.Worksheet
Dim xlsheet2 As Excel.Worksheet
Dim xlsheet3 As Excel.Worksheet
Set xlapp = New Excel.Application
Set xlbook = xlapp.Workbooks.Open("r:\Palletizing Preshift Agenda.xls")
Set xlsheet1 = xlbook.Worksheets("1st Shift")
Set xlsheet2 = xlbook.Worksheets("2nd Shift")
Set xlsheet3 = xlbook.Worksheets("3rd Shift")
shift = Me.cmbShift.Value
If shift = "1st" Then
ExcelData = xlsheet1.range("E5")
ElseIf shift = "2nd" Then
ExcelData = xlsheet2.range("E5")
ElseIf shift = "3rd" Then
ExcelData = xlsheet3.range("E5")
ElseIf shift = "2nd" Then
ExcelData = 0
End If
Me.txtLinkData.Value = ExcelData
End Sub