Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
| Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access 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 12th, 2008, 12:54 AM
Registered User
 
Join Date: Mar 2008
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Access Subform RecordSource Issue

Hi,

I have a main form (frmEnterValues) where I allow a user to select 3 criteria then click a button to open a new form (frmResults).

On frmResults I have 3 fields that show the values that were selected in frmEnterValues:
 ex. Field 1: ControlSource =[Forms]![frmEnterValues]![cboSpecies]

I also have a subform (subfrmResults) on frmResults. What I need to do is be able to dynamically set the rows shown on the subform via VBA since I have detailed logic to implement based on the 3 criteria the user entered originally. My simplest test is to use this in the subforms Form_Load method:

Me.RecordSource = "Select * from tblMasterWoodGrading"
Me.Requery

My subform is tied to frmResults with my SourceObject = "subfrmResults". I've tried linking child and master fields but unfortunately I only get the first row returned from my table tblMasterWoodGrading. I've also tried removing the linking child and master fields but the returned data is somehow still filtered.

When I open my subform subfrmResults on it's own it correctly pulls back all rows from my table tblMasterWoodGrading.

Any assistance to get the appropriate rows to show based on a query I dynamically create in VBA would be greatly appreciated.

Thanks,
Lynn

 
Old March 12th, 2008, 06:35 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Do you have more information on the structure and relationships of the tables here? I am not sure why you would use a subform when the parent form doesn't really have a recordsource. Use a main form and just display the selected values using the On Current event in 3 unbound text boxes. Then create the recordsource for the parent table (it looks like, I don't have all the structure data). I would be inclined to put a WHERE clause on the button on the first form that launches the second form, something like:

Dim sLink As String
Dim sFirstParam As String
Dim sSecondParam As String
Dim sThirdParam As String

sFirstParam = Me.cboSpecies
sSecondParam = Me.cboSecond
sThirdParam = Me.cboThird

sLink = "[Species] = '" & sFirstParam & "' AND [Second] = '" & sSeconrdParam & "' AND [Third] = '" & sThirdParam & "'"

DoCmd.OpenForm sDocName, , , sLink

This assumes your parameters are strings.

Then use the on current event to display the parameters on the form. I would be inclined to use Public variables to hold these values to display in unbound text boxes on the second form.

Without the table structure, however, it is hard to propose an informed solution.

HTH


mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old March 12th, 2008, 11:51 AM
Registered User
 
Join Date: Mar 2008
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you very much! I quickly tested what you said and it appears to be filtering correctly. I won't be able to test more until later tonight but it looks like your advice will work - I was making it too complicated. Thanks!!!

 
Old March 12th, 2008, 01:04 PM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

If you are really going to use this, you will probably want to test for parameter selections. Assuming the user MUST select First param, but doesn't need to select Second param, you could do this:

'Mandatory selection:
If IsNull(Me.cboSpecies) Or Me.cboSpecies = 0 Then 'assumes number
   MsgBox "Please select a species.", vbCritical
   Exit Sub
Else
   sFirstParam = Me.cboSpecies
End If

'Selection not required:
If IsNull(Me.cboSecond) Or Me.cboSecond = "" Then 'assumes text
   sSecondParam = ""
Else
   sSecondParam = Me.cboSecond
End If

...


This prevents errors being thrown if the user does not make a selection or doesn't make all of them. Any or all of them may be optional or mandatory.

mmcdonal

Look it up at: http://wrox.books24x7.com




Similar Threads
Thread Thread Starter Forum Replies Last Post
Array as recordsource for Report prasanta2expert Access VBA 1 March 14th, 2008 04:21 PM
Recordsource Scripts82 Access VBA 4 March 7th, 2006 03:04 AM
Access SubForm Problem jscully Access 9 August 29th, 2005 03:03 PM
Changing Report's RecordSource ! penta Access 11 April 30th, 2005 11:48 AM
AC2000 - Subform Issue mgpa Access VBA 0 October 18th, 2004 06:49 AM





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