Hello again; as usual, I will begin with a bit of explanation. Sorry if this gets long-winded:
I have a report – not written by me – that my company uses as an invoice. The report was originally designed to list Product Options directly under the product name on the invoice. It allows for 10 options, each of which is in a separate field in the Order Details table (Option01, Option02, Option03, etc.). I’m attaching a screencap of what the Orders screen looks like for reference purposes. Note that on the Orders screen, these are referenced as Option1, Option2, etc., rather than Option01, Option 02, etc.
This is the original code. If there is something in the Product Options field for a particular line item, the code inserts a hard return after the product name, inserts a “ – “, and then inserts whatever is in the appropriate Product Option field.
Some time ago, we decided to, uh, hijack one of the Product Option fields so that we could accommodate line-item purchase orders from our customers (we don’t have any actual Product Options).
We decided that we would use Option02 as the field for line item purchase orders. I was able to modify the original code – I suspect with help from someone on this very board – so that, if there was something in the Option02 field, it would insert “PO – “ instead of the usual “ – “ before putting in the content of the Option02 field.
It has been working like a charm. I have attached a screencap of the report generated with this modification.
So now we get to the next thorny issue. We have decided that, in addition to line-item purchase orders, we need to support line item Fund Codes. We selected the Option01 field for Fund Codes. I initially thought that this would be a simple tweak. I thought wrong.
I’ve tried a number of different bits of code so that we could add the “Fund Code” label to the report, all of which have failed to one degree or another. In the worst cases, it blew up the report completely and I had to restore from my backup copy (I always make a backup copy before I start). Errors galore, I’m afraid. The code manages to not crash the report, and it does add the “Fund Code” label, but it also puts the content of the Option01 field into the report again, this time preceded by the “ – “ (see third screencap).
I’m convinced this is tied to the [FONT="]ElseIf y <> Me("txtOp2") & "" Then [/FONT][FONT="]line, but don’t know how to solve it. [/FONT] I initially thought I could just change the line to [FONT="]ElseIf y <> Me("txtOp1") & "" OR y <> Me("txtOp2") & "" Then[/FONT][FONT="] but that got me one of Microsoft’ s illegal procedure warnings. From what I’ve gleaned from googling, I now think you can’t put an OR in an ElseIf statement, but I don’t know how to craft a line which does something like “check to see if there’s something in Option01, if so, add ‘Fund Code’ in front of it, and then move on to see if there is something in Option02.” [/FONT]
[FONT="]I’m hoping that by the time I get back into the office on Monday, someone here will have told me where I went wrong.[/FONT]
[FONT="]Thanks![/FONT]
I have a report – not written by me – that my company uses as an invoice. The report was originally designed to list Product Options directly under the product name on the invoice. It allows for 10 options, each of which is in a separate field in the Order Details table (Option01, Option02, Option03, etc.). I’m attaching a screencap of what the Orders screen looks like for reference purposes. Note that on the Orders screen, these are referenced as Option1, Option2, etc., rather than Option01, Option 02, etc.
This is the original code. If there is something in the Product Options field for a particular line item, the code inserts a hard return after the product name, inserts a “ – “, and then inserts whatever is in the appropriate Product Option field.
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim x$, y$, i%
x = ""
For i = 1 To 10
y = Me("txtOp" & i) & ""
If y > "" Then
If x > "" Then x = x & cr
x = x & " - " & y
End If
Next
If x > "" Then x = cr & x
Me.txtProduct = Me.txtItem & "" & x
If Me.Adjustment Then
Me.txtShowSKU = ""
Else
Me.txtShowSKU = Me.txtSKU
End If
End Sub
We decided that we would use Option02 as the field for line item purchase orders. I was able to modify the original code – I suspect with help from someone on this very board – so that, if there was something in the Option02 field, it would insert “PO – “ instead of the usual “ – “ before putting in the content of the Option02 field.
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim x$, y$, i%
x = ""
For i = 1 To 10
y = Me("txtOp" & i) & ""
If y > "" Then
'If there is anything in Option02, this inserts "PO - " in front of it
If y = Me("txtOp2") & "" Then
If x > "" Then x = x & cr
x = x & " PO - " & y
ElseIf y <> Me("txtOp2") & "" Then
'End inserted code
If x > "" Then x = x & cr
x = x & " - " & y
End If
End If
Next
If x > "" Then x = cr & x
Me.txtProduct = Me.txtItem & "" & x
If Me.Adjustment Then
Me.txtShowSKU = ""
Else
Me.txtShowSKU = Me.txtSKU
End If
End Sub
So now we get to the next thorny issue. We have decided that, in addition to line-item purchase orders, we need to support line item Fund Codes. We selected the Option01 field for Fund Codes. I initially thought that this would be a simple tweak. I thought wrong.
I’ve tried a number of different bits of code so that we could add the “Fund Code” label to the report, all of which have failed to one degree or another. In the worst cases, it blew up the report completely and I had to restore from my backup copy (I always make a backup copy before I start). Errors galore, I’m afraid. The code manages to not crash the report, and it does add the “Fund Code” label, but it also puts the content of the Option01 field into the report again, this time preceded by the “ – “ (see third screencap).
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim x$, y$, i%
x = ""
For i = 1 To 10
y = Me("txtOp" & i) & ""
If y > "" Then
'New Code to insert "fund code"
If y = Me("txtOp1") & "" Then
If x > "" Then x = x & cr
x = x & " Fund Code: " & y
End If
'Original code
'If there is anything in Option02, this inserts "PO - " in front of it
If y = Me("txtOp2") & "" Then
If x > "" Then x = x & cr
x = x & " PO - " & y
ElseIf y <> Me("txtOp2") & "" Then
'End inserted code
If x > "" Then x = x & cr
x = x & " - " & y
End If
End If
Next
If x > "" Then x = cr & x
Me.txtProduct = Me.txtItem & "" & x
If Me.Adjustment Then
Me.txtShowSKU = ""
Else
Me.txtShowSKU = Me.txtSKU
End If
End Sub
[FONT="]I’m hoping that by the time I get back into the office on Monday, someone here will have told me where I went wrong.[/FONT]
[FONT="]Thanks![/FONT]