locked
Compile Error: Method or Data Member not Found - VBA Word 2007 RRS feed

  • Question

  • Hi,

    From a Newb. I searched to no avail to get help with this simple program that exports text from Access to a Word doc.  Here is the code that is giving me the  error message on compiling:

    Public Sub WordXPort()
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim fld As Field

    Set db = CurrentDb()
    Set rs = db.OpenRecordset("Headers")
    Set fld = rs.Fields(0)

    WordEx

    Do Until rs.EOF
    sel.TypeText Text:="ENTRY - " & fld.Value & vbCrLf & vbCrLf
    rs.MoveNext
    Loop

    End Sub

    The underlined/bolded object is where the compiler finds the error.  Any help would be greatly appreciated.  Thanks!

    Tuesday, April 28, 2015 6:33 PM

Answers

  • Hi Bernie,

    The fix was to simply declare fld as DAO.Field.  Thanks for you help!

    • Marked as answer by Chiroacuman Wednesday, April 29, 2015 6:04 PM
    Wednesday, April 29, 2015 6:04 PM

All replies

  • Just use

    fld

    as in

    sel.TypeText Text:="ENTRY - " & fld & vbCrLf & vbCrLf

    Tuesday, April 28, 2015 7:50 PM
  • Thanks for the reply Bernie!

    That unfortunately didn't work, it gave me an error message, but I put a period after field and noticed that there was no, "Value" option, so I used, "Data" (as in fld.Data) and it compiled but now I have a problem with:

    Set fld = rs.Fields(0)  -  Gives me a, "Type Mismatch" runtime error.

    I'm having trouble with this, if you have time to address it that would be nice, otherwise thanks for responding to my question.

    Wednesday, April 29, 2015 12:49 AM
  • Try using the name of the field - which of course depends on the table:

    Set fld = rs.Fields("Address")

    If you have the example file Address book database.accdb, try this code with that DB file active as an example:

    Public Sub WordXPortAddressBookDatabase()
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim fld As Field

    Set db = CurrentDb()
    Set rs = db.OpenRecordset("Addresses")
    Set fld = rs.Fields("Address")

    'WordEx  'Not sure what this does

    Do Until rs.EOF
    'sel.TypeText Text:="ENTRY - " & fld & vbCrLf & vbCrLf   'Don't do anything with Word
    MsgBox "ENTRY - " & fld 
    rs.MoveNext
    Loop

    End Sub


    Wednesday, April 29, 2015 1:58 PM
  • Hi Bernie,

    The fix was to simply declare fld as DAO.Field.  Thanks for you help!

    • Marked as answer by Chiroacuman Wednesday, April 29, 2015 6:04 PM
    Wednesday, April 29, 2015 6:04 PM