docmd.openform subform where question

Posted on 2006-03-20
Last Modified: 2012-05-05
I have the following code as part of a command buttons onclick event:
DoCmd.OpenForm "Adult MIF subform", , , "[Member ID]=" & Me![Member ID], , acHidden

The whenever I click the button, I get "The OpenForm action was canceled." message and then nothing happens.

Probably something easy, but this used to work until I added the where clause part, so its probably something with that part of it.  Any ideas as to how to fix this? I want the subform record related to the current main form record to open in the background for some other processing.  
Question by:lorenkii
    LVL 39

    Expert Comment

    You can get this message when there is no data to display.  Put a code break on the line and see what value is in Me![Member ID].  Make sure that value exists in  [Member ID] of the record source of "Adult MIF subform".  Also remove the "acHidden" so yoncon see what is going on with "Adult MIF subform".

    Author Comment

    You are correct, it seems like it the two are not connecting, because when I make the subform that opens visible the member ID is blank, not the same as the one on the main form.  The id's are text fields, which they need to be since some of the ids are alphanumeric, but when I change them to be integers for the purpose of my test, the whole thing works fine.  So maybe I am not accounting for the text variables properly?  Any ideas?
    LVL 39

    Accepted Solution

    You need to add apostrophes for text fields:
    "[Member ID]='" & Me![Member ID] "'"
    apostrophes  _/\ ________________/\

    VBA data type-declaration characters:
    String: bracket with quotation marks or apostrophes (required)
    Example: "this is a string" or 'This is a string'

    Date/Time: Bracket with pound signs (required)
    Example: #6/1/1947#, #June 17, 1999#, #3:30pm#, #1/5/63 2:33#

    Number (Base 10): No type-declaration character needed (The number will automatically be converted to the type needed)
    Example: 1234, 67.77

    Hexadecimal number: precede with &h
    Example: &H10

    0ctal number: precede with &O
    Example: &O10

    Optionally, you can also explicitly specify the data type:
    Integer: Append with percent sign
    Example: 1234%

    Long: Append with ampersand  
    Example: 67877768&

    Currency: Append with at sign
    Example: 62.45@

    Single: Append with exclamation point  
    Example: 123.777!, 67.00!

    Double: Append with number sign
    Example: 677767.8888#

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
    Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now