Private Sub Auto_Open()
'--------------------------------------------------
'Tasks to run automatically when workbook is opened
'--------------------------------------------------
Dim sfilename As String
Dim temp As Double
Dim ttotalfilename As String
Dim wkbsource As Workbook
Dim salesdatafields As Variant
If CommandBars("Ribbon").Height > 100 Then
Application.SendKeys ("^{F1}") 'make sure ribbon is minimised
MsgBox ("minimised") 'temporary notification
End If
'set up comboboxes on sales data settings worksheet
salesdatafields = Array("Empty", "Transaction Number", "Item Code", "Item Description", "Quantity", "Net Price Per Item", "Payment Method 1", "Payment Amount 1", "Payment Method 2", "Payment Amount 2", "Payment Method 3", "Payment Amount 3", "Payment Method 4", "Payment Amount 4", "Gross Price Per Item", "Sale Total", "Time of Sale", "Sale Memo", "Tax Class", "Till Currency", "Date of Sale", "Till Number", "Sale Number")
Sheet20.ComboBox1.List = salesdatafields
Sheet20.ComboBox2.List = salesdatafields
Sheet20.ComboBox3.List = salesdatafields
Sheet20.ComboBox4.List = salesdatafields
Sheet20.ComboBox5.List = salesdatafields
Sheet20.ComboBox6.List = salesdatafields
Sheet20.ComboBox7.List = salesdatafields
Sheet20.ComboBox8.List = salesdatafields
Sheet20.ComboBox9.List = salesdatafields
Sheet20.ComboBox10.List = salesdatafields
Sheet20.ComboBox11.List = salesdatafields
Sheet20.ComboBox12.List = salesdatafields
Sheet20.ComboBox13.List = salesdatafields
Sheet20.ComboBox14.List = salesdatafields
Sheet20.ComboBox15.List = salesdatafields
Sheet20.ComboBox16.List = salesdatafields
Sheet20.ComboBox17.List = salesdatafields
Sheet20.ComboBox18.List = salesdatafields
Sheet20.ComboBox19.List = salesdatafields
Sheet20.ComboBox20.List = salesdatafields
Sheet20.ComboBox21.List = salesdatafields
Sheet20.ComboBox22.List = salesdatafields
Sheet20.ComboBox23.List = salesdatafields
Sheet20.ComboBox24.List = salesdatafields
Sheet20.ComboBox25.List = salesdatafields
Sheet20.ComboBox26.List = salesdatafields
Sheet20.ComboBox1.Value = Sheet20.Cells(5, 8)
Sheet20.ComboBox2.Value = Sheet20.Cells(6, 8)
Sheet20.ComboBox3.Value = Sheet20.Cells(7, 8)
Sheet20.ComboBox4.Value = Sheet20.Cells(8, 8)
Sheet20.ComboBox5.Value = Sheet20.Cells(9, 8)
Sheet20.ComboBox6.Value = Sheet20.Cells(10, 8)
Sheet20.ComboBox7.Value = Sheet20.Cells(11, 8)
Sheet20.ComboBox8.Value = Sheet20.Cells(12, 8)
Sheet20.ComboBox9.Value = Sheet20.Cells(13, 8)
Sheet20.ComboBox10.Value = Sheet20.Cells(14, 8)
Sheet20.ComboBox11.Value = Sheet20.Cells(15, 8)
Sheet20.ComboBox12.Value = Sheet20.Cells(16, 8)
Sheet20.ComboBox13.Value = Sheet20.Cells(17, 8)
Sheet20.ComboBox14.Value = Sheet20.Cells(18, 8)
Sheet20.ComboBox15.Value = Sheet20.Cells(19, 8)
Sheet20.ComboBox16.Value = Sheet20.Cells(20, 8)
Sheet20.ComboBox17.Value = Sheet20.Cells(21, 8)
Sheet20.ComboBox18.Value = Sheet20.Cells(22, 8)
Sheet20.ComboBox19.Value = Sheet20.Cells(23, 8)
Sheet20.ComboBox20.Value = Sheet20.Cells(24, 8)
Sheet20.ComboBox21.Value = Sheet20.Cells(25, 8)
Sheet20.ComboBox22.Value = Sheet20.Cells(26, 8)
Sheet20.ComboBox23.Value = Sheet20.Cells(27, 8)
Sheet20.ComboBox24.Value = Sheet20.Cells(28, 8)
Sheet20.ComboBox25.Value = Sheet20.Cells(29, 8)
Sheet20.ComboBox26.Value = Sheet20.Cells(30, 8)
Application.EnableEvents = False 'turn off events so we don't cause an error when we write to the current sale worksheet
'make sure the appropriate worksheets are protected
Sheet1.Protect
Sheet5.Protect
Sheet6.Protect
Sheet7.Protect
Sheet8.Protect
Sheet9.Protect
Sheet10.Protect
Sheet11.Protect
Sheet12.Protect
Sheet13.Protect
Sheet14.Protect
Sheet15.Protect
Sheet16.Protect
Sheet17.Protect
Sheet18.Protect
Sheet19.Protect
Sheet20.Protect
'make sure the 'main options' worksheet is visable, all other worksheets are hidden
Sheet5.Visible = xlSheetVisible
Sheet1.Visible = xlSheetHidden
Sheet2.Visible = xlSheetHidden
Sheet3.Visible = xlSheetHidden
Sheet4.Visible = xlSheetHidden
Sheet6.Visible = xlSheetHidden
Sheet7.Visible = xlSheetHidden
Sheet8.Visible = xlSheetHidden
Sheet9.Visible = xlSheetHidden
Sheet10.Visible = xlSheetHidden
Sheet11.Visible = xlSheetHidden
Sheet12.Visible = xlSheetHidden
Sheet13.Visible = xlSheetHidden
Sheet14.Visible = xlSheetHidden
Sheet15.Visible = xlSheetHidden
Sheet16.Visible = xlSheetHidden
Sheet17.Visible = xlSheetHidden
Sheet18.Visible = xlSheetHidden
Sheet19.Visible = xlSheetHidden
Sheet20.Visible = xlSheetHidden
'make sure option to printout receipts is enabled
Sheet1.CheckBox1 = True
'make sure option to print the £ rate of VAT on the receipt if we are using a different currency is enabled
Sheet18.CheckBox1 = True
'set previous sale change as 0
Sheet1.Unprotect
Sheet1.Cells(5, 10) = 0
'set till total to zero
Sheet1.Cells(3, 10) = 0
'set sale number to 1
Sheet1.Cells(2, 10) = 1
Sheet1.Protect
'make sure excel can display any necessary alerts
Application.DisplayAlerts = True
Application.EnableEvents = True
'make sure userforms are hidden and set up as necessary
UserForm1.savebutton.Enabled = False
UserForm1.Hide
UserForm2.Hide
UserForm3.Hide
UserForm4.Hide
UserForm5.Hide
UserForm6.Hide
UserForm7.Hide
'set the 'main options' worksheet as the first sheet that the user will see
Sheet5.Activate
'show welcome screen
UserForm8.Show
'check the directories which we store data in exist
On Error Resume Next
Err.Clear
If Dir(Sheet11.Cells(18, 4), vbDirectory) = "" Then MkDir (Sheet11.Cells(18, 4)) 'check epos data directory exists
If Dir(Sheet11.Cells(18, 4) + "systemdata\", vbDirectory) = "" Then MkDir (Sheet11.Cells(18, 4) + "systemdata\") 'check system data directory exists
If Err.Number <> 0 Then MsgBox ("WARNING!! The directory currently set as the storage directory for the EPOS data does not exist. Please update the file settings!"): Exit Sub
On Error GoTo 0
'make sure there the till total data file if it exists only relates to todays till totals - if it contains till totals from another date delete it
ttotalfilename = Sheet11.Cells(18, 4) + "systemdata\tilltotaldata.xlsx"
If Dir(ttotalfilename) <> "" Then
Application.ScreenUpdating = False
Set wkbsource = Workbooks.Open(ttotalfilename, ReadOnly:=True)
'cell (1,2) in the till total data file always contains the date the till totals in the file relate to
If wkbsource.Sheets(1).Cells(1, 2) <> Date Then
wkbsource.Close
Kill (ttotalfilename)
Else
wkbsource.Close
End If
Application.ScreenUpdating = True
End If
'clear product list which is held locally in this workbook and then update it
Sheet3.Cells.Clear
Call updateproductdata
End Sub