Results 1 to 5 of 5
  1. #1
    vickan240sx is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    May 2012
    Posts
    34

    Compile Error: Can't find out what's wrong with the code.

    Hi,

    I am new to Access. I entered the following code, but I'm getting a compile error over the ".Access_Bar_Code"


    Code:
    Private Sub Access_Bar_Code_BeforeUpdate(Cancel As Integer)
    
        Dim SID As String
        Dim stLinkCriteria As String
        Dim rsc As DAO.Recordset
    
        Set rsc = Me.RecordsetClone
    
        SID = Me.Access_Bar_Code.Value
        stLinkCriteria = "[Access Bar Code]=" & "'" & SID & "'"
    
        'Check Legal Files table for duplicate Access Bar Code
        If DCount("Access_Bar_Code", "Legal Files", _
                  stLinkCriteria) > 0 Then
            'Undo duplicate entry
            Me.Undo
            'Message box warning of duplication
            MsgBox "WARNING: " _
                 & SID & " has already been entered." _
                 & vbCr & vbCr & "You will now been taken to that record.", _
                   vbInformation, "Duplicate Information"
            'Go to record of original Access Bar Code
            rsc.FindFirst stLinkCriteria
            Me.Bookmark = rsc.Bookmark
        End If
    
        Set rsc = Nothing
    End Sub
    If somebody can help me, that will be great.



    Thank you very much.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Given the different ways you have it there, my guess would be that the actual control has spaces rather than underscores. Spaces in object names are not worth the bother in the long run.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Yes, when spaces or special characters or punctuation (underscore is exception) are used in names or are a reserved word, must enclose with [].
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    vickan240sx is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    May 2012
    Posts
    34
    Quote Originally Posted by June7 View Post
    Yes, when spaces or special characters or punctuation (underscore is exception) are used in names or are a reserved word, must enclose with [].
    Oh, ok. I'll keep in mind to never use spaces for column headers. Thanks for your help.

    I'll try the brackets.

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    With some exceptions in VBA coding, the same goes for names of tables, queries, forms, reports, controls.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Why do I get a compile error?
    By shabbaranks in forum Programming
    Replies: 24
    Last Post: 10-18-2011, 07:51 PM
  2. Replies: 6
    Last Post: 09-28-2011, 09:20 PM
  3. Compile error: code or function not defined
    By GeorgeBrown in forum Access
    Replies: 1
    Last Post: 09-19-2011, 10:25 AM
  4. new compile error!
    By darklite in forum Access
    Replies: 6
    Last Post: 09-02-2010, 05:13 PM
  5. Replies: 23
    Last Post: 03-26-2009, 06:50 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