Need Help With Runtime errors

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • copleyuk
    New Member
    • May 2010
    • 39

    #1

    Need Help With Runtime errors

    I have inherited a database and a number of tasks to complete regarding its design...

    The one causing me the trouble is a form in which people enter data.
    I need this form to return the correct information if an existing reference number is entered or allow new data to be entered if the reference number does not exist.

    I have gone through a number of forums etc trying to get this working but it seems everytime I try one thing I get a new error message and I'm just going in circles!!

    Please help!

    I'm fairly new to VBA so go easy on me :)
    Code:
    Private Sub RefrenceNumber_BeforeUpdate(Cancel As Integer)
        Dim rs As DAO.Recordset
    
                   Set rs = Me.RecordsetClone
            rs.FindFirst "[refrencenumber] = " & Me.RefrenceNumber
                        Me.Bookmark = rs.Bookmark
                    Set rs = Nothing
    
    End Sub
    This is one of my attempts which is giving me a run-time 3070 error.
    Last edited by NeoPa; May 5 '10, 05:13 PM. Reason: Please use the [CODE] tags provided.
  • Megalog
    Recognized Expert Contributor
    • Sep 2007
    • 378

    #2
    Code:
    Private Sub RefrenceNumber_BeforeUpdate(Cancel As Integer)
        Dim rs As DAO.Recordset
    
        Set rs = Me.Recordset.Clone
        rs.FindFirst "[refrencenumber] = " & Me.RefrenceNumber
        If rs.NoMatch = False Then
            Me.Undo
            Me.Bookmark = rs.Bookmark
        End If
        Set rs = Nothing
    End Sub
    If 'refrencenumber ' is actually a text format, not number, then use this in line #5:

    Code:
        rs.FindFirst "[refrencenumber] = '" & Me.RefrenceNumber & "'"
    Last edited by Megalog; May 5 '10, 06:08 PM. Reason: code variant (for numeric field matching)

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32669

      #3
      In a rush now, but a couple of points :
      1. You spell reference number [RefrenceNumber].
      2. The error message (as opposed to the error code on its own) would be helpful information.

      Comment

      • copleyuk
        New Member
        • May 2010
        • 39

        #4
        Thanks for taking the time to respond guys,

        Megalog has cracked it for me with the line 5 change!

        Thanks alot

        Carl

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32669

          #5
          In that case you may be interested in a little light reading on the matter (Quotes (') and Double-Quotes (") - Where and When to use them).

          Comment

          Working...