Results 1 to 3 of 3
  1. #1
    guroth is offline Novice
    Windows 8 Access 2013
    Join Date
    Feb 2014
    Posts
    2

    Form as standalone and subform...

    Have problem with a form i want to use as both a standalone form and a subform.



    The scenario:
    Form_Customer (the main form)
    Form_Customer_Orders (the form i want to use as both standalone and subform)
    And in Form_Customer_Orders i have a listbox_orders with a list of orders

    listbox_orders have this rowsource "SELECT * FROM Orders WHERE CustomerID = [Forms]![Form_Customer_Orders]![CustomerID]"
    This works well when i use the form as a standalone.

    However if i use it as a linked subform in Form_Customer i get error on the [Forms]![Form_Customer_Orders]![CustomerID] as it not loaded.
    If i change the rowsource for the listbox to "SELECT * FROM Orders WHERE CustomerID = [Forms]![Form_Customer]![CustomerID]" it works as a linked subform but not a standalone form anymore.

    How do i solve this?
    I could do it with vba but is there not a better way?

    // Regards Guroth

  2. #2
    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
    You can use the OnLoad event of the Form in question to determine if it was opened independently or as a Subform with code like this:
    Code:
    Private Sub Form_Load()
      If SysCmd(acSysCmdGetObjectState, acForm, "Name of Form Goes Here") = 0 Then
       'Code for opening as Subform goes here
     Else
       'Code for opening as an independent Form goes here
     End If
    End Sub


    Linq ;0)>

  3. #3
    guroth is offline Novice
    Windows 8 Access 2013
    Join Date
    Feb 2014
    Posts
    2
    Thanks, this is pretty much what i am doing now.
    Just feels bit messy writing long querys in vb for the rowsource in vb.

    Wish there was a "Me![Field]" reference you could do in the query that would reference to the controls owner form.
    But as i understad there is no such thing

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

Similar Threads

  1. Replies: 2
    Last Post: 01-02-2014, 07:53 AM
  2. Replies: 3
    Last Post: 11-03-2013, 01:04 PM
  3. Replies: 9
    Last Post: 10-29-2013, 02:41 PM
  4. Converting to Standalone Executable
    By JeffGeorge in forum Programming
    Replies: 3
    Last Post: 08-15-2013, 02:32 PM
  5. Access for standalone
    By TheShabz in forum Access
    Replies: 14
    Last Post: 11-12-2011, 04:15 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