Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 5th, 2008, 04:05 AM
Authorized User
 
Join Date: Sep 2006
Posts: 73
Thanks: 6
Thanked 0 Times in 0 Posts
Default Subdatasheet in VBA

 Hello all:

I have a form that opens up named "Order_Form". I have a Lookup command button on it. When I click 'Lookup' then the code listed below runs and a read-only datasheetview window open using the Orders table. What I would like to do is create a subdatasheet using vba to link it to the Orders_Detail table via OrderName. Can that be done?

Thanks,
Tony


My code:
=================================================
Private Sub cmdSearchOrders_Click()
    Dim db As Database
    Dim QD As QueryDef
    Dim where As Variant
    Set db = CurrentDb()

    On Error Resume Next
    db.querydefs.Delete ("Orders_Dynamic_Query")
    On Error GoTo 0

    where = Null
    If Not IsNull(Me![scboOrderName]) Then
        where = where & " AND [OrderName] = '" + Me.scboOrderName + "'"
    End If

    If Not IsNull(Me![scboOrderType]) Then
        where = where & " AND [OrderType] = '" + Me.scboOrderType + "'"
    End If

    Set QD = db.CreateQueryDef("Orders_Dynamic_Query", _
    "Select * from Orders " & (" where " + Mid(where, 6) & ";"))
    DoCmd.OpenQuery "Orders_Dynamic_Query", , acReadOnly

End Sub

 
Old June 5th, 2008, 10:07 AM
Authorized User
 
Join Date: Sep 2006
Posts: 73
Thanks: 6
Thanked 0 Times in 0 Posts
Default

I did it another way..

I created a form called Orders_Dynamic_Query_Form and set it as a datasheet linked to my Orders_Dynamic_Query from my Search code. I then created a subform called Orders_Dynamic_Query_Subform and set it as a datasheet for my Orders_Revision Table and linked the ordername fields together from the Orders_Dynamic_Query and the Orders_Revision_Table. I dragged the subform to the main form and replace the following code in my search subroutine

DoCmd.OpenQuery "Orders_Dynamic_Query", , acReadOnly

with this:
DoCmd.OpenForm "Orders_Dynamic_Query_Form", acFormDS, , , acFormReadOnly, acDialog


It works great.






Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA help davidbrooks Visual Basic 2008 Essentials 2 March 26th, 2008 07:25 PM
Code works in Excel VBA but not Access VBA fossx Access VBA 2 May 21st, 2007 08:00 AM
Subdatasheet problem IanB Access 0 August 23rd, 2006 10:16 PM
New to VBA. Please help me. rupen Access VBA 1 May 27th, 2005 07:54 AM
Excel VBA to SQL & back to VBA edesousa Excel VBA 1 June 1st, 2004 02:39 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.