Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
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 February 12th, 2004, 12:44 PM
Registered User
 
Join Date: Feb 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Opening forms to point to a particular record.

I have a sub-form within a form. In this sub form I have a continuous form show the data from a table I want to be able to open the record in another form from double clicking on the record within the continues form. I can get into the On Double Click function; I'm just having problems with the coding behind it.
The other thing that I would like to be able to do is to open the selected record from a button on the main form (the one with the sub-form within it.

Please Help.
Simon
 
Old February 14th, 2004, 05:25 PM
Authorized User
 
Join Date: Oct 2003
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

1st request is,
On dblclick event code
DoCmd.OpenForm "frmFormName",, Forms.frmNewForm.txtID = Me.txtID
bear with me here, syntax may be off, I'm trusting you get the idea.

2nd request,
if I understand correctly, you want to filter the subform via a button on the main form. Is it correct that, the button offers one fixed value. only?
You will have to change the recordsource on the subform with the new "statement" from the button. Depending on how the default recordsource is derived, you will have to alter it with an SQL statement. In short, it is the recordsource of the subform that allows you to control the recordset it displays.
There is also a filter property that I haven't used yet, but I suspect that roughly, the same results can be obtained.
I hope I'm on the right track.
Good luck!

 
Old February 16th, 2004, 05:33 PM
Registered User
 
Join Date: Feb 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for replying I'm having trouble getting the code to work. I've replaced 'frmFormName' with the appropriate form name, 'Work_Orders' and then when I ran it and realised that I needed the end 'txtID' replaced with the Primary key from the record source 'WO_ID'.
On running it this time I have 'Object Doesn't Support This Property or Method'. Can anyone see what I've done wrong? the line of code now looks like;
DoCmd.OpenForm "frmFormName", , Forms.frmNewForm.txtID = Me.WO_ID

Thanks for your help
 
Old February 16th, 2004, 05:48 PM
Authorized User
 
Join Date: Jun 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try this.....

DoCmd.OpenForm "frmFormName",,Forms!frmNewForm.txtID = " & Me.WO_ID

HTH,
Mike
 
Old February 17th, 2004, 06:34 PM
Registered User
 
Join Date: Feb 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your help but I'm having real problems getting it to work. The code now looks like;

DoCmd.OpenForm "Work_Orders", , Forms!Work_Orders.WO_ID = " & Me.WO_ID"

When I double click on the relevant text box it tells me 'Microsoft Access can't form 'Work_Orders' referred to in a macro expression or visual basic code.'
Having played around with the code I found that it was the Work_Orders just before .WO_ID. The table I'm trying to open is called Work_Orders, both the current form and the one I'm trying to open have an identical record source I'm just really stuck for how to do it.

Thank you
Simon
 
Old February 17th, 2004, 07:26 PM
Authorized User
 
Join Date: Jun 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Simon,

You are missing a " in front of Forms and remove the quote at the end of the WO_ID


DoCmd.OpenForm "Work_Orders", , "Forms!Work_Orders.WO_ID = " & Me.WO_ID

HTH,
Mike
 
Old February 17th, 2004, 07:40 PM
Authorized User
 
Join Date: Jun 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Simon,

I just thought of something...you shouldn't have to qualify the field in the where clause of the openform method.

DoCmd.OpenForm "Work_Orders", , "WO_ID = " & Me.WO_ID

The WO_ID in quotes is the one in the recordsource on form Work_Orders and Me.WO_ID refers to the control called WO_ID is from the form in which this code resides.

HTH,
Mike
 
Old February 18th, 2004, 06:40 AM
Registered User
 
Join Date: Feb 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thankyou for replying. I've tryed both, they both work it's just that they are pointing to the first record no matter which rescord you click on. Help!
Simon
 
Old February 22nd, 2004, 04:29 PM
Registered User
 
Join Date: Feb 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thankyou for all of your help I've now sorted it out all it needed was an extra ',' in there.
DoCmd.OpenForm "Work_Orders", , , "WO_ID = " & Me.WO_ID

Thank you

Simon





Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening 1 form from 2 forms rocknrisk Access 5 July 29th, 2005 06:05 PM
Help with opening and closing forms Dwizz VB.NET 2002/2003 Basics 4 April 21st, 2005 03:19 AM
opening and closing forms mp VB.NET 2002/2003 Basics 6 April 2nd, 2005 07:37 PM
how can I speed up the opening of forms? Mihai B Access VBA 6 March 14th, 2005 06:05 AM
Closing and Opening Forms Louisa VB.NET 2002/2003 Basics 1 February 5th, 2004 02:40 PM





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