Wrox Programmer Forums
|
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 July 29th, 2005, 04:15 AM
Authorized User
 
Join Date: Jul 2005
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rocknrisk
Default Opening 1 form from 2 forms

Hi all,

Please can someone help. I need to open a form "frmViewContact", with a preselected record in it from 2 buttons, each on a different form.

frmA has cmdViewContact (criteria from a combobox, cboContactID)
frmB has cmdViewContact (criteria from a combobox, cboContactID)

Here is my so far incorrect code.

Each button has a Click Event Procedure:

Private Sub cmdViewContact_Click() *** on frmCalls ***
    Dim strContact As String
    strContact = "SELECT mtblContacts.*, mtblContacts.idsContactID FROM mtblContacts " _
        & " WHERE ((mtblContacts.idsContactID) Like [Forms]![frmCalls]![cboContactID])"

    DoCmd.OpenForm "frmViewContact"
    With Forms!frmViewContact
        .SetFocus
        .RecordSource = strContact
        .Requery
    End With
End Sub

AND

Private Sub cmdViewContact_Click() *** on frmTransactions ***

    Dim strContact As String
    strContact = "SELECT mtblContacts.*, mtblContacts.idsContactID FROM mtblContacts " _
        & " WHERE ((mtblContacts.idsContactID) Like [Forms]![frmTransactions]![cboContactID])"

    DoCmd.OpenForm "frmViewContact"
    With Forms!frmViewContact
        .SetFocus
        .RecordSource = strContact
        .Requery
    End With
End Sub

The idea is to set the RecordSource for frmViewContact in code. How do I pass the parameter directly to this form depending on which button I access it from? At the moment it the little parameter input dialog comes up (I don't want that) and I have a SubForm on frmViewContact which only shows if I manually fill in the parameter input dialog.

I hope this all makes sense. Please help. Any help is greatly appreciated.

Thank you in advance,
Clinton

 
Old July 29th, 2005, 10:17 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

'---------- Code Starts ----------

Dim stDocName As String
Dim stContact As Integer
Dim stLink As String

stContact = Me.cboContactID
stLink = "[idsContactID] = " & stContact
stDocName = "frmViewContact"

DoCmd.OpenForm stDocName, acNormal, , stLink

'---------- Code Ends ----------

Put this code on each buttons' On Click event.
Bind the form to mtblContacts

HTH


mmcdonal
 
Old July 29th, 2005, 04:32 PM
Authorized User
 
Join Date: Jul 2005
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rocknrisk
Default

Hey mmcdonal,

Cheers for your help. Unfortunately it still don't work. I still get a dilog box come up before frmViewContact opens saying, "Enter parameter value for mtblContacts.idsContactID". cboContactID should give this parameter. I can't understand why it's not passing the variable.

Any ideas.

Thanks again in advance,
Clinton
 
Old July 29th, 2005, 04:36 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

How many columns are you retrieving in your combo box? If you retrieve more than 1, you need to tell it which column to use.

Kevin

dartcoach
 
Old July 29th, 2005, 06:02 PM
Authorized User
 
Join Date: Jul 2005
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rocknrisk
Default

Kevin,

You're a genius. Many thanks.

Why are the hardest things always the simplest?

Cheers,
Clinton
 
Old July 29th, 2005, 06:05 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

You're more than welcome.
Kevin

dartcoach





Similar Threads
Thread Thread Starter Forum Replies Last Post
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
Opening forms from other forms Paulsh Access VBA 1 September 30th, 2004 06:54 PM
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.