Results 1 to 3 of 3
  1. #1
    Steven19 is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2020
    Location
    London
    Posts
    110

    Error - On Click Object Variable or With block variable not set

    Hi I have the below code which I took from a tutorial which looked to work well.

    I have this behind an command button.

    The issue is I get the following error:
    The expression On Click you entered as the event property setting produced the following error: Object variable or WIth block variable not set.

    The expression may not result in the name of a macro, the name of a user-defined function, or [Event Procedure]
    There may have been an error evaluating the function, event, or macro.

    This is happening on a access runtime as the company who have my database do not have a full ms access version.


    Private Sub Command6_Click()
    Dim Msg As String


    Msg = "Dear Business Support,<P>" & _
    "A New Accident has been recorded in the Accidents Database for you to review."


    Dim O As Outlook.Application
    Dim M As Outlook.MailItem


    Set O = New Outlook.Application


    Set M = O.CreateItem(olMailItem)


    Set M = Nothing
    Set O = Nothing


    With M
    .BodyFormat = olFormatHTML
    .HTMLBody = Msg
    .To = "bss@seabrookgroup.com"
    .Subject = "New Accident Report " & Now()
    .Send
    End With


    DoCmd.OpenForm "FrmTodaysRecords"
    DoCmd.Close acForm, Me.Name, acSaveNo


    End Sub

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,522
    Set M = Nothing
    Set O = Nothing
    END SUB

    both go at the end after youre done with them.
    Don't erase them before you use them.

  3. #3
    Steven19 is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2020
    Location
    London
    Posts
    110
    Hi Thanks

    This now works

    Regards

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 05-14-2021, 08:39 AM
  2. Replies: 6
    Last Post: 03-19-2020, 01:53 PM
  3. Error 91 Object Variable or Block Variable Not Set
    By mindbender in forum Programming
    Replies: 5
    Last Post: 05-01-2017, 12:01 PM
  4. Replies: 6
    Last Post: 02-11-2016, 02:05 PM
  5. Replies: 0
    Last Post: 08-10-2011, 11:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums