Results 1 to 5 of 5
  1. #1
    tariq1 is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    May 2012
    Posts
    16

    Compile Error: Argument not optional

    Hi, I am receiving the error with the code below, thank you for your assistance




    Compile Error: Argument not optional


    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If Me![FirstName].Value = Tariq Then
    MsgBox ''Tariq already exists''
    Cancel = True
    End If
    End Sub

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    If Tariq is a literal string then must be enclosed in quote marks.
    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.

  3. #3
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    To elaborate on what June7 said - you have delimited your string Tariq already exists with pairs of single quotes - instead of a pair of single quotes, you need to use double quotes:

    "Tariq already exists"

    The compiler is interpreting the first of your single quotes as the start of a comment following MsgBox, leaving MsgBox with no message, thus the error

    John


  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Good catch, John, I didn't even notice those were single quotes. My comment was about the string Tariq in the If condition.
    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.

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    In addition, testing for duplicates on a Field is normally done in the BeforeUpdate event of the Control where the Field Value is entered, not in the Form_BeforeUpdate event.

    If you only want one Record for 'Joe,' you want to find out that 'Joe' already has a Record immediately after entering his name, not after entering all of his data for a second, unnecessary time, when the Record is being saved!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. Replies: 2
    Last Post: 06-23-2012, 11:59 PM
  2. Replies: 7
    Last Post: 06-08-2012, 09:55 PM
  3. Replies: 7
    Last Post: 11-17-2011, 02:56 PM
  4. Replies: 6
    Last Post: 09-28-2011, 09:20 PM
  5. Compile Error: Argument Not Optional
    By bg18461 in forum Access
    Replies: 1
    Last Post: 12-01-2010, 08:47 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