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 March 26th, 2004, 11:01 AM
Registered User
 
Join Date: Mar 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default requery subform

I have been battling with a Access form and subform.

The information on the master form is brought in via visual basic (with a combo box as the catalist). There is a subform which I need to
run through a sql query and I do this through the querydefs function, the problem I have is that the query updates fine but regardles of what I try I can not get the subform to update with the revised information in the query.

I have been looking at the forums and tried many ideas, alas none have worked.
If anyone can help I will be very grateful.

 
Old March 26th, 2004, 11:35 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

After you update the data on the main form, try using:

Me.subformname.SourceObject = MySQLCriteria

Where you replace "subformname" with your subform's real name and MySQLCriteria is a string containing your SQL statement.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old March 26th, 2004, 12:01 PM
Registered User
 
Join Date: Mar 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the advice, just a little unclear as to how to dispaly the sql statement.

I create the query via: CurrentDb.QueryDefs("showsales").SQL = strsql

this is done through a function called salesquery, which compiles the string.

So I have used: (in line with your suggestion) and it does not appear to work.
Me.showsalesfrm.SourceObject = salesquery(strsql)

 
Old March 26th, 2004, 01:49 PM
Authorized User
 
Join Date: Feb 2004
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Assuming that you can't relate the Subform to the parent through the sub form Property Sheet, Data tab, Link Child Fields and Link Master Fields properties, then you will have to requery the specific instance of the subform. Please note that a subform may be open on one or more instances of a single parent form or even a variety of different parent forms so it is not enough to specify a requery of the form that is placed as a subform. You must specify the specific instance of the subform that needs to be requeried. Using a single saved querydef is not practical in an environment where the form may be open on more than one place at one time. You would then be better off to directly set the RecordSource sql string (2nd syntax below).

Assume the source object form is named 'frmSales' and the name you have given the subform control on a parent form is 'sfrmSales', you can requery the subform with code from the parent with the following syntax:

Me.sfrmSales.Form.Requery

Generally speaking, assigning the recordsource property will also force a requery. An alternate syntax would be:

Me.sfrmSales.Form.RecordSource = CurrentDb.QueryDefs("showsales").SQL = strsql

or

Me.sfrmSales.Form.RecordSource = strsql


or

Me.sfrmSales.Form.RecordSource = "showsales"

where 'showsales' is the name of the querydef

Ciao
Jürgen Welz
Edmonton AB Canada
[email protected]
 
Old March 29th, 2004, 11:50 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Quote:
quote:Originally posted by bpete
Me.showsalesfrm.SourceObject = salesquery(strsql)
Is SalesQuery is a function that creates an SQL string based on strSQL? If so, this should work provided that the function type that SalesQuery puts out is string and is a valid SQL query. Also, are you putting it on the Form's AfterUpdate event?


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old March 30th, 2004, 09:31 AM
Registered User
 
Join Date: Mar 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for the suggestions guys, i have got round the problem by using the Me.subformname.SourceObject suggestion and just pulling a different form in the subform box.

Cheers






Similar Threads
Thread Thread Starter Forum Replies Last Post
Subform Record Saved, Update/Requery Form controls CB-VTXer Access VBA 2 August 6th, 2007 02:35 PM
Requery a subform aware Access 3 December 27th, 2005 12:25 PM
Requery SubForm lizhaskin Access 1 November 28th, 2005 02:19 PM
Filter Subform B Based on Field in Subform A SerranoG Access VBA 3 June 18th, 2004 12:23 AM
SubForm Requery ppenn Access VBA 2 August 7th, 2003 02:00 AM





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