Results 1 to 3 of 3
  1. #1
    Nancy is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Location
    NH
    Posts
    10

    Question VBA Code + regx

    Hi,

    First, I know very little about VBA.

    We have recently upgraded from Access 2007 to Access 2010. A module with VBA function was written for me by a Microsoft Pro. The code exports a query and saves it on our file server as an Excel file. The code includes emailing the Excel spreadsheet to several people. This is done because the code is initated from a macro in the database that is run from a scheduled task on our file server daily.

    When I copied a previous module to a new Access 2010 database and tried to run, I get the error message "Complie Error - User-defined type not defined". The error is on the code "Dim regx As New RegExp". We can no longer get help from our Microsoft Pro. Can anyone help me? The VBA code is below.

    Option Compare Database
    Public Function getSortFormula(formula As String)
    Dim strNewFormula As String
    Dim regx As New RegExp

    strNewFormula = formula
    If Left(strNewFormula, 1) = "C" Then

    Set regx = New RegExp

    regx.Pattern = "^C[0-9]*H([^egf]|.*)"
    regx.Global = False
    regx.IgnoreCase = False
    If regx.Test(formula) Then
    strNewFormula = Replace(strNewFormula, "H", "ZZZ", 1, 1, vbTextCompare)
    End If

    regx.Pattern = "^C[^0-9asroemfl]"
    If regx.Test(strNewFormula) Then
    strNewFormula = Replace(strNewFormula, "C", "C1", 1, 1, vbTextCompare)
    End If



    End If

    getSortFormula = strNewFormula
    End Function

    Public Function EmailDailyMargin()
    DoCmd.OutputTo acOutputQuery, "qry_Daily CGS Review", acFormatXLSX, "G:\Nancy\Task\DailyMarginReview.xlsx"

    Set objMessage = CreateObject("CDO.Message")
    objMessage.Subject = "DailyMarginReview"
    objMessage.Sender = "Nancy@strem.com"
    objMessage.To = "Nancy@strem.com;"
    objMessage.TextBody = "Previous work day sales margins to review. Nancy"
    objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/con...tion/sendusing") = 2
    objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/con...ion/smtpserver") = "exmail"
    objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/con...smtpserverport") = 25
    objMessage.Configuration.Fields.Update
    objMessage.AddAttachment "G:\Nancy\Task\DailyMarginReview.xlsx"
    objMessage.Send
    End Function

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    In your references , make sure you include the
    Microsoft VBScript Regular Expressions 5.5
    <----- the later versions may be different (it may not be 5.5)

  3. #3
    Nancy is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Location
    NH
    Posts
    10
    This fixed the problem! Thank you very much.

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

Similar Threads

  1. VBA Code Help Please
    By jo15765 in forum Programming
    Replies: 8
    Last Post: 01-15-2011, 01:00 PM
  2. Word code in Access - How to modify my current code
    By Alexandre Cote in forum Programming
    Replies: 0
    Last Post: 11-15-2010, 08:26 AM
  3. Code in combobox, code in text box
    By float in forum Forms
    Replies: 3
    Last Post: 09-29-2010, 07:12 AM
  4. Help with VBA code
    By bgonzal1 in forum Access
    Replies: 3
    Last Post: 12-14-2009, 07:12 AM
  5. Access 2003 code vs Access 2007 Code
    By ralphjramirez in forum Access
    Replies: 5
    Last Post: 11-23-2009, 12:33 PM

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