Calculated Field Not Correct

tkepongo

Registered User.
Local time
Today, 05:04
Joined
Jul 15, 2011
Messages
45
In my report, there is a textbox that displays the Buyer's name for a purchase order. The Buyer's name is determined by the first two digits of the purchase order number.

Code:
Dim Buyer As String
Buyer = Left(Me.PurchaseOrder, 2)
If Buyer = 23 Then
    Me.txtBuyer = "Buyer1 Name"
End If
If Buyer = 33 Then
    Me.txtBuyer = "Buyer2 Name"
End If

If Buyer = 30 Then
    Me.txtBuyer = "Buyer3 Name"
End If

I have that code in the On_Current event and it works if I click the individual record in Report View. However, the buyer's name is reflected in all the records. In Print Preview, it shows blank.

I need to print the reports and have it display the correct Buyer's name for each record. How can I do this?

PS: If I put the code in the On_Load event, it shows only one Buyer's name for all records.
 
The code should go in the Format event of the Detail section.

But you could consider creating a BuyerNames table.
 
This type of thing would go in the detail format event (or the format event of the section containing the textbox). That event only fires in Preview and Print views, not Report view. I would probably use the Switch() function instead of code, but if you stick with code either using ElseIf or Select/Case would be more efficient than what you have.
 
I used the Format event and it works. Thank you everyone!
 

Users who are viewing this thread

Back
Top Bottom