locked
Trying to figure out how to fill a access table with all the fonts on my pc. RRS feed

  • Question

  • Trying to figure out how to fill a access table with all the fonts on my pc.

    At least the fonts with the extension of TTF   true type font

    In directory of C:\Windows\Fonts

    Several ways I have tried have not worked.

    I only need the name as a string stored in the table.

    Last thing I tried was the old cbo filing code.  The one that is a function with arg list (fld as control, id as variant, row as variant, col as variant)

    Is dir no longer good keyword?             Was used repeatedly to get next file in same directory with same extension.


    Mark J

    Thursday, August 18, 2016 1:15 PM

Answers

All replies

  • In the Immediate window (Ctrl+G):

    ?dir("c:\windows\fonts\*.ttf")
    AGENCYB.TTF

    Does that not work for you?


    -Tom. Microsoft Access MVP

    Thursday, August 18, 2016 1:23 PM
  • How about http://www.devhut.net/2015/10/15/vba-enumerate-fonts/ ?

    Daniel Pineault, 2010-2012 Microsoft MVP
    http://www.cardaconsultants.com
    MS Access Tips and Code Samples: http://www.devhut.net

    • Marked as answer by PuzzledByWord Sunday, August 21, 2016 10:49 AM
    Thursday, August 18, 2016 1:45 PM
  • Or how about

    Public Function ListMyFont(Optional sPath As String = "C:\Windows\Fonts\", _
                          Optional sFilter As String = "*")
        On Error GoTo Error_Handler
        Dim sFile                 As String

        sFile = Dir(sPath & "*." & sFilter)
        Do While sFile <> vbNullString
            If sFile <> "." And sFile <> ".." Then
                Debug.Print sFile
                'Do something with the found file
            End If
            sFile = Dir
        Loop

    Error_Handler_Exit:
        On Error Resume Next
        Exit Function

    Error_Handler:
        MsgBox "The following error has occured." & vbCrLf & vbCrLf & _
               "Error Number: " & Err.Number & vbCrLf & _
               "Error Source: ListMyFont" & vbCrLf & _
               "Error Description: " & Err.Description, _
               vbCritical, "An Error has Occured!"
        Resume Error_Handler_Exit
    End Function

    and simply call it like so:

    Call ListMyFont( , "ttf")


    Daniel Pineault, 2010-2012 Microsoft MVP
    http://www.cardaconsultants.com
    MS Access Tips and Code Samples: http://www.devhut.net

    • Proposed as answer by Chenchen Li Friday, August 19, 2016 8:23 AM
    Thursday, August 18, 2016 1:50 PM
  • Daniel,

    It worked great.

    I got output like  FontName.TTF

    I was trying to get just the name so I changed

     sFile = Dir(sPath & "*." & sFilter)    to

     sFile = Dir(sPath)   thinking I would get file name without the extension of TTF

    I was wrong, and surprised. Got a lot more fonts some like Roman.fon    turns out that is a valid font.

    from Microsoft copyrighted in 1985.

    Thanks,

    Mark J


    Mark J

    Sunday, August 21, 2016 10:40 AM
  • Tom,

    I had no idea "dir" could be used this way and.

    it works and I got the same result.   Only one font.  I am a bit curious why only one font returned. except maybe it might be the first on the list and the code might only return one value.

    But I am trying to fill a table in access of all fonts. to be used in recordset and a function.

    Thanks,

    Mark J


    Mark J

    Sunday, August 21, 2016 10:46 AM
  • Daniel Pineault,

    the link to the vba-enumerate-fonts

    seemed a bit strange to use word in access to get values in access.

    BUT WORKED! great no problems.  I was able to change to fill a table easy.  and importantly no extensions.

    I did get some curious results   got several like this

    Meiryo UI

    and

    @Meiryo UI                                  I even cut and pasted into the format box of the cbo used to pick what font to use on a control    and as far as I could tell    on a few fonts   didn't make any difference if had the @ in front or not.  or used like this   txtbox.fontName=@Meiryo UI   or txtbox.fontName=Meiryo UI

    was a few out of the 291 fonts that had the   @      and some that had  same font name with and without the @.

    want to thank you again for the various ways so I could find one that works best for me.

    also i want to thank you again, and share this curious result.   Like to know if anyone does know about why the  @    but i do NOT need to know to finish this project.

    Mark J


    Mark J

    Sunday, August 21, 2016 11:04 AM