Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 5th, 2008, 04:05 AM
Authorized User
Points: 336, Level: 6
Points: 336, Level: 6 Points: 336, Level: 6 Points: 336, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2006
Location: , , .
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

Reply With Quote
  #2 (permalink)  
Old June 5th, 2008, 10:07 AM
Authorized User
Points: 336, Level: 6
Points: 336, Level: 6 Points: 336, Level: 6 Points: 336, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2006
Location: , , .
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.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:13 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.