Changing Text Color From Database 追蹤
Hi,
I'm trying to set up a label where the text color is supplied by a database field in the document's OnNewRecord event.
If I use this logic:
ReferenceField("BILL.Color")
dim mColor
mColor = Field("BILL.Color")
Format.Objects("Text 1").TextColor = mColor
I get an error from the last line - Type mismatch. If I put a message box before that line it returns my database value ie:btRed
If I do the following it works, but I don't want to have to do this for every possible color the database may contain:
ReferenceField("BILL.Color")
dim mColor
mColor = Field("BILL.Color")
msgbox(mColor)
Select Case mColor
Case "btColor.Orange"
Format.Objects("Text 1").TextColor = BtColor.Orange
Case "btColor.Blue"
Format.Objects("Text 1").TextColor = BtColor.Blue
Case "btColor.Red"
Format.Objects("Text 1").TextColor = BtColor.Red
Case else
Format.Objects("Text 1").TextColor = BtColor.Black
end select
7 意見
Hello Billo4th,
Could you please clarify what exact value you've stored on your database?
Note that "btRed" is not a value that will be accepted by the "TextColor" property. Actualkly if you want it red it will accept "Red" directly, or "BtColor.Red".
Please consult BarTender's Help to find a full list of accepted colors (run a search for "BtColor object").
Regards.
Fernando,
Sorry for my typo, the values in my database are BtColor.Red, BtColor.Blue, etc. It just seems that I can't use the data field directly
Format.Objects("Text 1").TextColor = Field("BILL.Color")
or read it into a variable and then use the variable
mColor = Field("BILL.Color")
Format.Objects("Text 1").TextColor = mColor
Bill
Hello Bill,
Could you let me know exactly when are you getting this error message?
Please note that when working on the "OnNewRecord" event and with database fields in your script, the database data won't be loaded until you actually send a print job. Being that the case, when you use field references you will usually get an error message when closing the script assistant, not because the code is wrong, but because the database field is empty or the default data is not "compatible" with what you are doing with it.
Do test doing a print preview or directly sending a print job with your previous code, and let me know if that generated an error too.
Regards.
If I use either of my prior examples I do not get an error when I test the code, and no error saving it. The error ONLY happens with
a print preview or direct print. The exact error message window is:
BarTender: Error Message #3904
The following script error occurred:
OnNewRecord(line 12): : Type mismatch: 'Format.Objects(...).TextColor
Where are you putting the VB script? To be able to manipulate the color of an object you need to be doing it in the BarTender Document options, not on a label object itself.
Go to File>BarTender Document Options, then the VB Scripting tab, your script should be here, not in an object on the label itself.
Go to File>BarTender Document Options>VB Scripting tab>OnNewRecord>Edit..
ReferenceField("Sheet1$.Color")
dim mColor
mColor = Field("Color")
If (mColor = "BtColor.Orange") Then
Format.Objects("Text 1").TextColor = BtColor.Orange
End If
If (mColor = "BtColor.Red") Then
Format.Objects("Text 1").TextColor = BtColor.Red
End If
If (mColor = "BtColor.Blue") Then
Format.Objects("Text 1").TextColor = BtColor.Blue
End If
If (mColor = "BtColor.Black") Then
Format.Objects("Text 1").TextColor = BtColor.Black
End If
請登入寫評論。