I've copied below exactly where I'm at in writing this code. For purposes of discussion I have put line numbers in front each line of code (down to a point that is useful).
What I'm trying to do is to record on a sheet called "Invoice TrackSheet" within the application a line label which I have name "ReturnPoint". There are many possible return points within the code. This line label is the point in the code at which I exited and will need to return to. When reopening a particular set of saved data I want to return to the point in the code at which I exited for that particular set of data which is saved on the "Invoice TrackSheet".
My problem is that line 40 "GoTo ReturnPoint" keeps giving me a undefined label error. I defined it within the project as Dim ReturnPoint As String.
That's all that I can think of to say here...if you need any clarifications I will gladly do so.
Thanks,
Steve
1 Public ImageWidth As String
2 Public ImageHeight As String
3 Public NumberofMats As String
4 Public MatNumber1StockNumber As String
5 Public ThisInvoiceNumber As Long
6 Public ThisWorkOrderNumber As Long
7 Public CustomerName As String
8 Public CustomerPhoneNumber As String
9 Public ContactName As String
10 Public DescriptionofWork As String
11 Public DueDate As String
12 Public WorkOrderNumber As String
13 Public InvoiceNumber As Long
14 Public IsNewInvoice As String
15 Sub Macro1()
16 ' Macro recorded 7/8/2009 by User
'
17 ' Keyboard Shortcut: Ctrl+o
'
18 Dim ReturnPoint As String
19 CustomerName = ""
20 CustomerPhoneNumber = ""
21 ContactName = ""
22 DueDate = ""
23 ImageWidth = ""
24 ImageHeight = ""
25 'Find out if a new invoice is being started or if an invoice is being continued
26 Sheets("BACKGROUND").Select
27 IsNewInvoice = MsgBox("Are you wanting to start a new invoice?", vbYesNo, "New Invoice?")
28 If IsNewInvoice = vbYes Then GoTo BeginNewInvoice:
29 If IsNewInvoice = vbNo Then GoTo ReopenCustomer:
30 'ReopenCustomer is for continuing an invoice that has already been started.
31 ReopenCustomer:
32 InvoiceNumber = InputBox("What invoice number would you like to reopen? Enter an ""E"" to exit")
33 If InvoiceNumber = "E" Or InvoiceNumber = "e" Then GoTo EndThisSubRoutine:
34 Range("A1:A9002").Select
35 Range("A1:A9002").Cells.Find(What:=InvoiceNumber, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Select
Date = ActiveCell.Offset(0, 1).Range("A1")
36 ReturnPoint = ActiveCell.Offset(0, 2).Range("A1")
37 CustomerName = ActiveCell.Offset(0, 3).Range("A1")
38 ContactName = ActiveCell.Offset(0, 4).Range("A1")
39 DueDate = ActiveCell.Offset(0, 5).Range("A1")
40 GoTo ReturnPoint
41 'BeginNewInvoice is for starting a new invoice
42 BeginNewInvoice:
43 Sheets("INVOICE TRACKSHEET").Select
44 Sheets("INVOICE TRACKSHEET").Unprotect
45 Range("B1").Select
46 Selection.End(xlDown).Select
47 ActiveCell.Offset(1, -1).Range("A1").Select
48 InvoiceNumber = ActiveCell.Value
49 ActiveCell.Offset(0, 1).Range("A1") = Date
50 Sheets("INVOICE TRACKSHEET").Protect
51 CustomerInfo:
52 WorkOrderNumber = 1
53 ThisWorkOrderNumber = InvoiceNumber & WorkOrderNumber
54 CustomerName = InputBox("Please enter the Customer's Name To exit without saving please enter .... E", "Customer's Name?", "E")
55 If CustomerName = "E" Or CustomerName = "e" Then GoTo EndThisSubRoutine
56 If CustomerName = "" Then GoTo CustomerInfo:
57 CustomerPhoneNumber = InputBox("Enter the customer's Phone Number To exit without saving please enter .... E", "Customer's Phone Number")
58 If CustomerPhoneNumber = "E" Or CustomerPhoneNumber = "e" Then GoTo EndThisSubRoutine:
59 ContactName = InputBox("Enter a contact name for this customer if the customer is a business name", "Not Required")
60 If ContactName = "E" Or ContactName = "e" Then GoTo EndThisSubRoutine:
'Save personal info on Work Order TrackSheet so that further info will be "savable".
61 Sheets("WORK ORDER TRACKSHEET").Select
62 Sheets("WORK ORDER TRACKSHEET").Unprotect
63 Range("A1").Select
64 Selection.End(xlDown).Select
65 ActiveCell.Offset(1, 0).Range("A1").Select
66 ActiveCell.Offset(0, 0).Range("A1") = ThisWorkOrderNumber
67ActiveCell.Offset(0, 1).Range("A1") = CustomerName
68 ActiveCell.Offset(0, 2).Range("A1") = Date
69 ActiveCell.Offset(0, 3).Range("A1") = CustomerPhoneNumber
70 ActiveCell.Offset(0, 4).Range("A1") = ContactName
71 Sheets("WORK ORDER TRACKSHEET").Protect
'At this point data has been put on Invoice TrackSheet and the Work Order TrackSheet and it is bes to save this data.
72 Workbook.Save
73GoTo DueDate:
'After the first work order is complete the program returns to the "WorkOrderNumberAssignment:" point if another work order is to be entered.
74WorkOrderNumberAssignment:
75 WorkOrderNumber = WorkOrderNumber + 1
76 If WorkOrderNumber < 26 Then GoTo DueDate:
77 'MsgBox("You have reached the maximum number of work orders that can be invoiced at one time. Hit the enter key and the invoice will be summarized and displayed so that you can finish this invoice....you may open another invoice by just starting a new order","Maximum Number of Work Orders has been reached",VbOK,)
77 If IsNewInvoice = vbYes Then GoTo BeginNewInvoice:
78 If IsNewInvoice = vbNo Then GoTo ReopenCustomer:
79DescriptionofWork:
80 DescriptionofWork = InputBox("Please enter a description of this project", "Short Description Please")
81 If DescriptionofWork = "" Then GoTo DescriptionofWork:
82 If DescriptionofWork = "E" Or DescriptionofWork = "e" Then GoTo EndThisSubRoutine:
83 ReturnPoint = "DescriptionofWork:"
84 If DescriptionofWork = "S" Or DescriptionofWork = "s" Then GoTo SaveWithoutFinishing:
85Quantity:
86 Quantity = InputBox("What Quantity of projects are the same size and framed the same?", "Please Enter the Quantity")
87 If Quantity = "" Then GoTo Quantity:
88 If Quantity = "E" Or Quantity = "e" Then GoTo EndThisSubRoutine:
89 ReturnPoint = "Quantity:"
90 If Quantity = "S" Or Quantity = "s" Then GoTo SaveWithoutFinishing:
91DueDate:
92SpecialDueDate = InputBox("Is there a special due date required Y = Yes N = No E = Exit this customer's order without saving S = Exit and save this customer's order", "Is this a rush order?")
93 If SpecialDueDate = "E" Or SpecialDueDate = "e" Then GoTo EndThisSubRoutine:
94 If SpecialDueDate = "Y" Or SpecialDueDate = "y" Then GoTo EnterSpecialDueDate:
95 ReturnPoint = "DueDate:"
96 If SpecialDueDate = "S" Or SpecialDueDate = "s" Then GoTo SaveWithoutFinishing:
97 If SpecailDueDate = "N" Or SpecialDueDate = "n" Then GoTo ImageWidth:
98 DueDate = Date + 10
99EnterSpecialDueDate:
100 DueDate = InputBox("What is the special date that this order needs to be complete by?", "Enter a date")
101 If DueDate = "E" Or DueDate = "e" Then GoTo EndThisSubRoutine:
102 ReturnPoint = "SpecialDueDate:"
103 If DueDate = "S" Or DueDate = "s" Then GoTo SaveWithoutFinishing:
104ImageWidth:
105 ImageWidth = InputBox("What is the image width?", "Image Width?")
106 If ImageWidth = "E" Or ImageWidth = "e" Then GoTo EndThisSubRoutine:
107 ReturnPoint = "ImageWidth:"
108 If ImageWidth = "S" Then GoTo SaveWithoutFinishing:
109ImageHeight:
110 ImageHeight = InputBox("What is the image height?", "Is this a rush order?")
111 If ImageHeight = "E" Or ImageHeight = "e" Then GoTo EndThisSubRoutine:
112 ReturnPoint = "ImageHeight:"
113 If ImageHeight = "S" Or ImageHeight = "s" Then GoTo SaveWithoutFinishing:
114NumberofMats:
115 NumberofMats = InputBox("How many mats are there? Enter 1 thru 6", "Enter Quantity of mats?")
116 If NumberofMats = 1 Or NumberofMats = 2 Or NumberofMats = 3 Or NumberofMats = 4 Or NumberofMats = 5 Or NumberofMats = 6 Then GoTo MatNumber1StockNumber:
117 MsgBox ("There is a limit of 6 mats...to add another mat please do another workorder for just a mat")
118GoTo NumberofMats:
119 If NumberofMats = "E" Or NumberofMats = "e" Then GoTo EndThisSubRoutine:
120 ReturnPoint = "NumberofMats:"
121 If DueDate = "S" Then GoTo SaveWithoutFinishing:
122MatNumber1StockNumber:
123 MatNumber1StockNumber = InputBox("What is TOP mat number (number 1 mat)", "Input stock number of mat")
124 If MatNumber1StockNumber = "E" Or MatNumber1StockNumber = "e" Then GoTo EndThisSubRoutine:
125 ReturnPoint = "MatNumber1StockNumber:"
126 If MatNumber1StockNumber = "S" Or MatNumber1StockNumber = "s" Then GoTo SaveWithoutFinishing:
127SaveWithoutFinishing:
128 Sheets("INVOICE TRACKSHEET").Select
129 Sheets("INVOICE TRACKSHEET").Unprotect
130 Range("A1:A9002").Select
131 Range("A1:A9002").Cells.Find(What:=InvoiceNumber, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Select
132 ActiveCell.Offset(0, 2).Range("A1") = ReturnPoint
133 ActiveCell.Offset(0, 3).Range("A1") = CustomerName
134 ActiveCell.Offset(0, 4).Range("A1") = CustomerPhoneNumber
135 If WorkOrderNumber = 1 Then GoTo 136RecordWorkOrderNumber1DataOnInvoiceTrackSheet:
If WorkOrderNumber = 2 Then GoTo RecordWorkOrderNumber2DataOnInvoiceTrackSheet:
RecordWorkOrderNumber1DataOnInvoiceTrackSheet:
ActiveCell.Offset(0, 5).Range("A1") = DescriptionofWork
GoTo RecordWorkOrderData:
RecordWorkOrderNumber2DataOnInvoiceTrackSheet:
ActiveCell.Offset(0, 9).Range("A1") = DescriptionofWork
GoTo RecordWorkOrderData:
'Continue with the reasoning above for each work order (future programming)
Sheets("INVOICE TRACKSHEET").Protect
RecordWorkOrderData:
Sheets("WORK ORDER TRACKSHEET").Select
Sheets("WORK ORDER TRACKSHEET").Unprotect
Range("A1:A9002").Select
Range("A1:A9002").Cells.Find(What:=ThisWorkOrderNumber, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Select
ActiveCell.Offset(0, 5).Range("A1") = DescriptionofWork
ActiveCell.Offset(0, 6).Range("A1") = Quantity
ActiveCell.Offset(0, 7).Range("A1") = DueDate
Sheets("WORK ORDER TRACKSHEET").Protect
Workbook.Save
EndThisSubRoutine:
SaveData = MsgBox("Do you want to save this customers info?", vbYesNo, "Save data?")
If SaveData = vbYes Then GoTo SaveWithoutFinishing:
Sheets("Command Page").Select
End Sub
What I'm trying to do is to record on a sheet called "Invoice TrackSheet" within the application a line label which I have name "ReturnPoint". There are many possible return points within the code. This line label is the point in the code at which I exited and will need to return to. When reopening a particular set of saved data I want to return to the point in the code at which I exited for that particular set of data which is saved on the "Invoice TrackSheet".
My problem is that line 40 "GoTo ReturnPoint" keeps giving me a undefined label error. I defined it within the project as Dim ReturnPoint As String.
That's all that I can think of to say here...if you need any clarifications I will gladly do so.
Thanks,
Steve
1 Public ImageWidth As String
2 Public ImageHeight As String
3 Public NumberofMats As String
4 Public MatNumber1StockNumber As String
5 Public ThisInvoiceNumber As Long
6 Public ThisWorkOrderNumber As Long
7 Public CustomerName As String
8 Public CustomerPhoneNumber As String
9 Public ContactName As String
10 Public DescriptionofWork As String
11 Public DueDate As String
12 Public WorkOrderNumber As String
13 Public InvoiceNumber As Long
14 Public IsNewInvoice As String
15 Sub Macro1()
16 ' Macro recorded 7/8/2009 by User
'
17 ' Keyboard Shortcut: Ctrl+o
'
18 Dim ReturnPoint As String
19 CustomerName = ""
20 CustomerPhoneNumber = ""
21 ContactName = ""
22 DueDate = ""
23 ImageWidth = ""
24 ImageHeight = ""
25 'Find out if a new invoice is being started or if an invoice is being continued
26 Sheets("BACKGROUND").Select
27 IsNewInvoice = MsgBox("Are you wanting to start a new invoice?", vbYesNo, "New Invoice?")
28 If IsNewInvoice = vbYes Then GoTo BeginNewInvoice:
29 If IsNewInvoice = vbNo Then GoTo ReopenCustomer:
30 'ReopenCustomer is for continuing an invoice that has already been started.
31 ReopenCustomer:
32 InvoiceNumber = InputBox("What invoice number would you like to reopen? Enter an ""E"" to exit")
33 If InvoiceNumber = "E" Or InvoiceNumber = "e" Then GoTo EndThisSubRoutine:
34 Range("A1:A9002").Select
35 Range("A1:A9002").Cells.Find(What:=InvoiceNumber, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Select
Date = ActiveCell.Offset(0, 1).Range("A1")
36 ReturnPoint = ActiveCell.Offset(0, 2).Range("A1")
37 CustomerName = ActiveCell.Offset(0, 3).Range("A1")
38 ContactName = ActiveCell.Offset(0, 4).Range("A1")
39 DueDate = ActiveCell.Offset(0, 5).Range("A1")
40 GoTo ReturnPoint
41 'BeginNewInvoice is for starting a new invoice
42 BeginNewInvoice:
43 Sheets("INVOICE TRACKSHEET").Select
44 Sheets("INVOICE TRACKSHEET").Unprotect
45 Range("B1").Select
46 Selection.End(xlDown).Select
47 ActiveCell.Offset(1, -1).Range("A1").Select
48 InvoiceNumber = ActiveCell.Value
49 ActiveCell.Offset(0, 1).Range("A1") = Date
50 Sheets("INVOICE TRACKSHEET").Protect
51 CustomerInfo:
52 WorkOrderNumber = 1
53 ThisWorkOrderNumber = InvoiceNumber & WorkOrderNumber
54 CustomerName = InputBox("Please enter the Customer's Name To exit without saving please enter .... E", "Customer's Name?", "E")
55 If CustomerName = "E" Or CustomerName = "e" Then GoTo EndThisSubRoutine
56 If CustomerName = "" Then GoTo CustomerInfo:
57 CustomerPhoneNumber = InputBox("Enter the customer's Phone Number To exit without saving please enter .... E", "Customer's Phone Number")
58 If CustomerPhoneNumber = "E" Or CustomerPhoneNumber = "e" Then GoTo EndThisSubRoutine:
59 ContactName = InputBox("Enter a contact name for this customer if the customer is a business name", "Not Required")
60 If ContactName = "E" Or ContactName = "e" Then GoTo EndThisSubRoutine:
'Save personal info on Work Order TrackSheet so that further info will be "savable".
61 Sheets("WORK ORDER TRACKSHEET").Select
62 Sheets("WORK ORDER TRACKSHEET").Unprotect
63 Range("A1").Select
64 Selection.End(xlDown).Select
65 ActiveCell.Offset(1, 0).Range("A1").Select
66 ActiveCell.Offset(0, 0).Range("A1") = ThisWorkOrderNumber
67ActiveCell.Offset(0, 1).Range("A1") = CustomerName
68 ActiveCell.Offset(0, 2).Range("A1") = Date
69 ActiveCell.Offset(0, 3).Range("A1") = CustomerPhoneNumber
70 ActiveCell.Offset(0, 4).Range("A1") = ContactName
71 Sheets("WORK ORDER TRACKSHEET").Protect
'At this point data has been put on Invoice TrackSheet and the Work Order TrackSheet and it is bes to save this data.
72 Workbook.Save
73GoTo DueDate:
'After the first work order is complete the program returns to the "WorkOrderNumberAssignment:" point if another work order is to be entered.
74WorkOrderNumberAssignment:
75 WorkOrderNumber = WorkOrderNumber + 1
76 If WorkOrderNumber < 26 Then GoTo DueDate:
77 'MsgBox("You have reached the maximum number of work orders that can be invoiced at one time. Hit the enter key and the invoice will be summarized and displayed so that you can finish this invoice....you may open another invoice by just starting a new order","Maximum Number of Work Orders has been reached",VbOK,)
77 If IsNewInvoice = vbYes Then GoTo BeginNewInvoice:
78 If IsNewInvoice = vbNo Then GoTo ReopenCustomer:
79DescriptionofWork:
80 DescriptionofWork = InputBox("Please enter a description of this project", "Short Description Please")
81 If DescriptionofWork = "" Then GoTo DescriptionofWork:
82 If DescriptionofWork = "E" Or DescriptionofWork = "e" Then GoTo EndThisSubRoutine:
83 ReturnPoint = "DescriptionofWork:"
84 If DescriptionofWork = "S" Or DescriptionofWork = "s" Then GoTo SaveWithoutFinishing:
85Quantity:
86 Quantity = InputBox("What Quantity of projects are the same size and framed the same?", "Please Enter the Quantity")
87 If Quantity = "" Then GoTo Quantity:
88 If Quantity = "E" Or Quantity = "e" Then GoTo EndThisSubRoutine:
89 ReturnPoint = "Quantity:"
90 If Quantity = "S" Or Quantity = "s" Then GoTo SaveWithoutFinishing:
91DueDate:
92SpecialDueDate = InputBox("Is there a special due date required Y = Yes N = No E = Exit this customer's order without saving S = Exit and save this customer's order", "Is this a rush order?")
93 If SpecialDueDate = "E" Or SpecialDueDate = "e" Then GoTo EndThisSubRoutine:
94 If SpecialDueDate = "Y" Or SpecialDueDate = "y" Then GoTo EnterSpecialDueDate:
95 ReturnPoint = "DueDate:"
96 If SpecialDueDate = "S" Or SpecialDueDate = "s" Then GoTo SaveWithoutFinishing:
97 If SpecailDueDate = "N" Or SpecialDueDate = "n" Then GoTo ImageWidth:
98 DueDate = Date + 10
99EnterSpecialDueDate:
100 DueDate = InputBox("What is the special date that this order needs to be complete by?", "Enter a date")
101 If DueDate = "E" Or DueDate = "e" Then GoTo EndThisSubRoutine:
102 ReturnPoint = "SpecialDueDate:"
103 If DueDate = "S" Or DueDate = "s" Then GoTo SaveWithoutFinishing:
104ImageWidth:
105 ImageWidth = InputBox("What is the image width?", "Image Width?")
106 If ImageWidth = "E" Or ImageWidth = "e" Then GoTo EndThisSubRoutine:
107 ReturnPoint = "ImageWidth:"
108 If ImageWidth = "S" Then GoTo SaveWithoutFinishing:
109ImageHeight:
110 ImageHeight = InputBox("What is the image height?", "Is this a rush order?")
111 If ImageHeight = "E" Or ImageHeight = "e" Then GoTo EndThisSubRoutine:
112 ReturnPoint = "ImageHeight:"
113 If ImageHeight = "S" Or ImageHeight = "s" Then GoTo SaveWithoutFinishing:
114NumberofMats:
115 NumberofMats = InputBox("How many mats are there? Enter 1 thru 6", "Enter Quantity of mats?")
116 If NumberofMats = 1 Or NumberofMats = 2 Or NumberofMats = 3 Or NumberofMats = 4 Or NumberofMats = 5 Or NumberofMats = 6 Then GoTo MatNumber1StockNumber:
117 MsgBox ("There is a limit of 6 mats...to add another mat please do another workorder for just a mat")
118GoTo NumberofMats:
119 If NumberofMats = "E" Or NumberofMats = "e" Then GoTo EndThisSubRoutine:
120 ReturnPoint = "NumberofMats:"
121 If DueDate = "S" Then GoTo SaveWithoutFinishing:
122MatNumber1StockNumber:
123 MatNumber1StockNumber = InputBox("What is TOP mat number (number 1 mat)", "Input stock number of mat")
124 If MatNumber1StockNumber = "E" Or MatNumber1StockNumber = "e" Then GoTo EndThisSubRoutine:
125 ReturnPoint = "MatNumber1StockNumber:"
126 If MatNumber1StockNumber = "S" Or MatNumber1StockNumber = "s" Then GoTo SaveWithoutFinishing:
127SaveWithoutFinishing:
128 Sheets("INVOICE TRACKSHEET").Select
129 Sheets("INVOICE TRACKSHEET").Unprotect
130 Range("A1:A9002").Select
131 Range("A1:A9002").Cells.Find(What:=InvoiceNumber, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Select
132 ActiveCell.Offset(0, 2).Range("A1") = ReturnPoint
133 ActiveCell.Offset(0, 3).Range("A1") = CustomerName
134 ActiveCell.Offset(0, 4).Range("A1") = CustomerPhoneNumber
135 If WorkOrderNumber = 1 Then GoTo 136RecordWorkOrderNumber1DataOnInvoiceTrackSheet:
If WorkOrderNumber = 2 Then GoTo RecordWorkOrderNumber2DataOnInvoiceTrackSheet:
RecordWorkOrderNumber1DataOnInvoiceTrackSheet:
ActiveCell.Offset(0, 5).Range("A1") = DescriptionofWork
GoTo RecordWorkOrderData:
RecordWorkOrderNumber2DataOnInvoiceTrackSheet:
ActiveCell.Offset(0, 9).Range("A1") = DescriptionofWork
GoTo RecordWorkOrderData:
'Continue with the reasoning above for each work order (future programming)
Sheets("INVOICE TRACKSHEET").Protect
RecordWorkOrderData:
Sheets("WORK ORDER TRACKSHEET").Select
Sheets("WORK ORDER TRACKSHEET").Unprotect
Range("A1:A9002").Select
Range("A1:A9002").Cells.Find(What:=ThisWorkOrderNumber, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Select
ActiveCell.Offset(0, 5).Range("A1") = DescriptionofWork
ActiveCell.Offset(0, 6).Range("A1") = Quantity
ActiveCell.Offset(0, 7).Range("A1") = DueDate
Sheets("WORK ORDER TRACKSHEET").Protect
Workbook.Save
EndThisSubRoutine:
SaveData = MsgBox("Do you want to save this customers info?", vbYesNo, "Save data?")
If SaveData = vbYes Then GoTo SaveWithoutFinishing:
Sheets("Command Page").Select
End Sub