Results 1 to 6 of 6
  1. #1
    DB88 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2014
    Posts
    110

    "Invalid use of Me keyword"

    Hello,



    I was compiling my VBA code before creating an ACCDE when I got the compile error "Invalid use of Me keyword". The code is in a class module and it runs perfectly when I initiate it from the form. The section of code is below. Any ideas?

    Private Sub cmdFilter_Click()
    'Purpose: Build up the criteria string from the non-blank search boxes, and apply to the form's Filter.
    Dim strWhere As String 'The criteria string
    Dim lngLen As Long
    If Me.filterRefuel = 1 Then
    strWhere = strWhere & "([AerialRefuelCapable]=""Yes"") AND "
    ElseIf Me.filterRefuel = 0 Then
    strWhere = strWhere & "([AerialRefuelCapable]=""No"") AND "
    End If
    ....
    ...
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I am confused. AFAIK, the Me reference can only be used in code behind forms and reports. You say code is in a class module yet the Sub is a Click event. By class module do you mean a form? In which case the Me should work.

    What field type is AerialRefuelCapable?
    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
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Stop using ME.

  4. #4
    DB88 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2014
    Posts
    110
    Sorry, yes it is the module for a Form. The Me does work when I'm initialing the code from the form. But when I do Dubug>Compile I get the error.

    AerialRefuelCapable is text field. Note: the debugger highlights the Me in "If Me.filterRefuel = 1 THen" line. filterRefuel is an unbound combo box on the form.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I don't know why the debugger does not like that line. I don't see anything wrong with it. And since the code works when run, is weird.

    Try as ranman suggests and use explicit form name instead.
    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.

  6. #6
    DB88 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2014
    Posts
    110
    It was my silly mistake. I forgot to delete an old module that I have since stop using. This section of code in that module was what was causing my problem. Sorry for wasting your time.

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

Similar Threads

  1. Replies: 5
    Last Post: 06-26-2013, 02:29 PM
  2. Replies: 4
    Last Post: 06-24-2013, 07:12 AM
  3. Replies: 13
    Last Post: 12-05-2011, 05:10 AM
  4. StrComp causing "Invalid use of Null" error
    By sephiroth2906 in forum Programming
    Replies: 5
    Last Post: 09-15-2011, 07:06 PM
  5. Update query from form "invalid use of null"
    By Lady_Jane in forum Programming
    Replies: 4
    Last Post: 08-16-2011, 01:37 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