Format() function problem
Posted on 2013-11-07
Within my application I am writing a label printing routine. The user can design a label specifying the font size and other parameters of various text boxes which appear on the label when the label report is opened. I found that when I applied a value to the Format property of a text box, this was ignored. I assumed this was because I was using unbound controls on my label report. So then I decided to use the format() function to format the value before I assigned it to the text box. Here is a simplified version of my code:
Dim MyFormat As String
Dim MyDate As String
Dim MyControl As Control
MyDate = Date()
MyFormat = "yyyy-mm-dd"
Set MyControl = Me![DateControl]
.Value = Format(MyDate, MyFormat) 'Error occurs here
Set MyControl = Nothing
What I find is that I get Error:13 - Type mismatch at the point the text box is assigned. I created a new empty database and put the above code in there. It works just fine. So there must be something external factor which is causing my problem. I've been scratching my head for half a day now. Can anyone help please?