Results 1 to 4 of 4
  1. #1
    karma is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    2

    Wink run time error 2465

    Hi...Please help....this code works but with one problem the feilds [Item] and [EmailAddress] both require an exclamation mark ! in front of them for it to work, this makes the results of the feilds display the first record from the table where as the feilds [Job Number] and [Job Name] don't require the !. so i get the right results from them.


    When i take the ! mark away from the feilds i get run time error 2465 "feild can't be found"...

    Code:
    Private Sub cmdJointApp_Click()
    On Error GoTo Macro6_Err
    Dim oOApp As Outlook.Application
    Dim oOMail As Outlook.MailItem
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim strSubject As String
    Dim strBody As String
    Dim strEmail As String
    Dim strJobNumber As String
    Dim sql As String
    
    With CodeContextObject
        strJobNumber = Me.Job_Number
    End With
    Call CombimneValuesJA
    
    Set oOApp = CreateObject("Outlook.Application")
    Set oOMail = oOApp.CreateItem(olMailItem)
    Set db = CurrentDb
     
          Set rs = db.OpenRecordset("TempItems", dbOpenDynaset)
           With rs
           rs.FindFirst "[Job Number] = ""strJobNumber"""
           
          If Not rs.NoMatch Then
            Exit Sub
        End If
       
                            
                sql = ![Items]
                strSubject = ([JobNumber] & " " & [Job Name] & " items ready for Joint Approval")
                strBody = ("The Factory requires joint approval on the following items, " & Chr(13) & Chr(10) & sql)
                strEmail = ![EmailAddress]
            End With
    With oOMail
    .To = strEmail
    .subject = strSubject
    .Body = strBody
    .Display
    End With
    Macro6_Err:
        MsgBox Error$
        Me.Undo
    Exit Sub
    End Sub

  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,722
    What are the fields in table

    "TempItems"

  3. #3
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    It means that the two fields [Items] and [EmailAddress] are in the recordset rs., but are not recognized as fields or controls on your form. Which is it you want them to be?

    The same idea goes for [Job Number] and [Job Name] - do you want the data from the recordset rs., or a form field?
    ![Job Number] and [Job Number] are not the same thing.

    If as you say ![Items] and ![emailaddress] are showing the wrong values, it means that rs.FindFirst "[Job Number] = ""strJobNumber""" is not finding the correct record. Your logic is wrong here:

    If Not rs.NoMatch Then
    Exit Sub
    End If

    What this does is exit the sub if the findfirst SUCCEEDS - the opposite of what you want, no? That is why you always get the first record - if findfirst fails, it stays on the first record. You want to take the Not out: If rs.NoMatch Then....

    HTH

    John

  4. #4
    karma is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    2
    Hi John, thanks for the help . i have got it working. First of all the feilds [Job number] & [Job Name] where giving me the correct value, that was where i was stumped....I thought that the values where coming directly from the table after opening recordset...well i was wrong!!! So i took your advice and added the feilds to the form and bingo it works....

    Once again thanks for the help.

    Dave

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

Similar Threads

  1. Replies: 5
    Last Post: 06-09-2012, 12:37 PM
  2. VBA Referencing Subform Control Error 2465
    By Jester0001 in forum Programming
    Replies: 3
    Last Post: 05-30-2012, 07:31 AM
  3. Run Time Error 2465
    By jo8701 in forum Programming
    Replies: 1
    Last Post: 02-08-2012, 12:01 PM
  4. Run Time Error 2465 In Report
    By desk4tbc in forum Programming
    Replies: 9
    Last Post: 09-06-2011, 08:00 PM
  5. Run-Time error '2465'
    By hawkins in forum Access
    Replies: 6
    Last Post: 08-19-2011, 04:07 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