Results 1 to 4 of 4

Thread: Help.. newbie struggling

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2014
    Posts
    1

    Help.. newbie struggling

    Hi,
    I have been struggling with the code below to get it to work and i cannot find the error.. i am running this is in vbe in outlook 2010 to export emails to access for a project. i get a compile error " invalid use of property" at the underlined and bold code word below (adOpenDynamic).. any help with the code or why i am receiving the error would be appreciated..thx in advance

    Sub ExportMailByFolder()

    'Export specified fields from each mail

    'item in selected folder.

    Dim ns As Outlook.NameSpace

    Dim objFolder As Outlook.MAPIFolder

    Set ns = GetNamespace("MAPI")

    Set objFolder = ns.PickFolder

    Dim adoConn As ADODB.Connection

    Dim adoRS As ADODB.Recordset

    Dim intCounter As Integer

    Set adoConn = CreateObject("ADODB.Connection")

    Set adoRS = CreateObject("ADODB.Recordset")

    'DSN and target file must exist.

    adoConn.Open "DSN=OutlookData;"

    adoRS.Open "SELECT * FROM email", adoConn _

    adOpenDynamic , adLockOptimistic

    'Cycle through selected folder.

    For intCounter = objFolder.Items.Count To 1 Step -1

    With objFolder.Items(intCounter)

    'Copy property value to corresponding fields

    'in target file.

    If .Class = olMail Then

    adoRS.AddNew

    adoRS("Subject") = .Subject

    adoRS("Body") = .Body

    adoRS("FromName") = .SenderName

    adoRS("ToName") = .To

    adoRS("FromAddress") = .SenderEmailAddress

    adoRS("FromType") = .SenderEmailType

    adoRS("CCName") = .CC

    adoRS("BCCName") = .BCC

    adoRS("Importance") = .Importance

    adoRS("Sensitivity") = .Sensitivity

    adoRS.Update

    End If

    End With

    Next

    adoRS.Close

    Set adoRS = Nothing

    Set adoConn = Nothing

    Set ns = Nothing

    Set objFolder = Nothing

    End Sub

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Help.. newbie struggling

    You are seriously in the wrong forum for this. CC is not a good place for serious questions. I've reported the thread so that it will get moved appropriately.

    I haven't used that kind of code in a decade, but I do have a question that may be relevant: Do you have that underscore in your actual code, or was that put in when you copied it over? If that underscore is in your real code, try removing it and making one line:

    adoRS.Open "SELECT * FROM email", adoConn, adOpenDynamic, adLockOptimistic
    My usual boring signature: Nothing

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: Help.. newbie struggling

    Welcome to VBForums

    Thread moved to the 'Office Development/VBA' forum.

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Help.. newbie struggling

    probably needs a reference to microsoft activex data objects (ADO)
    adOpenDynamic is an ADO constant but if unreferenced may be treated as an uninitialised variable, check its value at runtime

    if you require further help please edit your original post and enclose the code in code tags, to make it more readable
    [code] ........... /[code] put the / inside the bracket, not as i have it, for it to work correctly
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width