开发者

Inaccuracies using TextWidth() in VBA

开发者 https://www.devze.com 2023-01-11 03:38 出处:网络
I\'m trying to get the length of a string in order to format a report using VBA in Access 2000. Yes I know this old but it\'s what I\'ve been asked to do. I want to get the width of the string when pr

I'm trying to get the length of a string in order to format a report using VBA in Access 2000. Yes I know this old but it's what I've been asked to do. I want to get the width of the string when printed; exactly what TextWidth() is meant to return. What I'm finding is that for strings ranging for 4-20 characters the returned value can rang开发者_如何学运维e from exactly the right length to the correct length plus about an inch. This is too inaccurate for the formatting I wish to do. Is this common? I can't find any reference to this as a common problem but I've gone over and over the code and I'm fairly certain the function is just inaccurate ratehr than there being a logic problem.


Check the report's FontName and FontSize properties. If they are different than the field you are working with, you'll get wildly different results.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    MsgBox (Me.FontName & " ," & Me.FontSize)
    MsgBox (TextWidth("Test"))
    Me.FontName = Me.f2.FontName  'ariel
    Me.FontSize = Me.f2.FontSize  '8
    MsgBox (Me.FontName & " ," & Me.FontSize)
    MsgBox (TextWidth("Test"))
    Me.FontName = Me.f1.FontName  'ariel
    Me.FontSize = Me.f1.FontSize  '16
    MsgBox (Me.FontName & " ," & Me.FontSize)
    MsgBox (TextWidth("Test"))
End Sub

I'm still not sure how to set the report's font name and size though, I don't see anything in it's properties.

0

精彩评论

暂无评论...
验证码 换一张
取 消