I'm having a problem with the code I'm writing. It doesn't compile. Compiler gives an error message saying "expected array" at the following line:
VoucherYear = Trim(Str(Year(VoucherDate)))
The code first opens a user form. I trace the code and everything works fine in the user form. After the user form, the control is transferred to add_voucher() in the main module. Once the control is transferred to the add_voucher() in the main module, in the debug window VoucherDate still shows as 30/4/2013 but Year(VoucherDate) shows "expression not defined in context" while in the userform1, the same function Year(VoucherDate) in the debug windows shows 2013.
What is going on here? Any help would be greatly appreciated.
VoucherYear = Trim(Str(Year(VoucherDate)))
The code first opens a user form. I trace the code and everything works fine in the user form. After the user form, the control is transferred to add_voucher() in the main module. Once the control is transferred to the add_voucher() in the main module, in the debug window VoucherDate still shows as 30/4/2013 but Year(VoucherDate) shows "expression not defined in context" while in the userform1, the same function Year(VoucherDate) in the debug windows shows 2013.
What is going on here? Any help would be greatly appreciated.
Code:
Public VoucherDate As Date <- declared in the main module above any subroutines
' in userform1 code
............
VoucherDate = Format(TextBox1.Text, "dd-mm-yyyy")
End Sub '<- control goes to add_voucher() in the main module
' at this stage, trim(str(year(VoucherDate))) gives the expected string "2013"
Public Sub add_voucher()
Dim wb As Workbook
Dim thisWorkbookName As String
thisWorkbookName = ActiveWorkbook.Name
Call process_userform1_selection
......
Sub process_userform1_selection()
VoucherYear = Trim(Str([B][COLOR=#ff0000]Year[/COLOR][/B](VoucherDate))) '<- cannot compile the code. The word "Year" is highlighted.
VoucherMonth = Trim(MonthName(month(VoucherDate)))
......
Last edited: