Are you using dlookup to get your value? If so that returns a variant which may be the issue so suggest surrounding it with cdbl
Are you using dlookup to get your value? If so that returns a variant which may be the issue so suggest surrounding it with cdbl
Please use # icon on toolbar when posting code snippets.
Cross Posting: https://www.excelguru.ca/content.php?184
Debugging Access: https://www.youtube.com/results?sear...bug+access+vba
Can you not see in my first post that it is formatted as "Percent"? Hence my question... as it's not showing as a Percentage when it is formatted as a Percent.
Ajax and I both suggested running the text box control source through the CDbl function. Have you given that a shot?
have you looked at post #16?
this comment
implies you copied this to the format property, not the controlsource propertyAfter testing that access throws the code out like this ""=For"m"at(["d\isc"ou"n"t],Percent)"
And I don't understand your control source - if discount is on your form, you don't need forms!longformname.form and if it is on a subform you would have longformname.form.discount. And anyway, forms!longformname.form.discount is not a valid path. The only other option is it would be on a completely separate form would appear to not be open anyway and would be forms!longformname.discount. So how are you getting it to work?
Hello Ajax & kd2017, yes, the Suppliers table has a field of DiscountPercentageID which looks up to the SuppliersDiscount table which has two fields 1) DiscountPercentageID and 2) Percent. The data in Percent is formatted as Percent.
I need to research what the CDbl function is.
The query returns the percent, however, when I fetch the value it doesn't display as the percent it should.
Not sure what I am doing wrong.
In your discount % text box control soure where it says =[Forms]![blah blah blah] send all that through the CDbl function so it looks like =CDbl([Forms]![blah blah blah])
CDbl is short for convert double. I see now that your source is a column from a combo, that column is a string I'm guessing. CDbl should convert it back to a decimal number that access understands how to display as a percentage.
This worked! =Format([Discount],"Percent") as the control source, thanks Minty. Sorry for all the questions and back and forth on this one! All, thanks for helping.
See it in action!
and the reason it is being treated as text is that you are getting it via a combo - the data presented in a combo or listbox is treated as text
and by the way, now you have used the format function rather than the property, the value is definitely text - so you cannot use it in any calculations