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
Password Reminder
Register
| FAQ | Members List | Calendar | 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 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 July 29th, 2005, 04:15 AM
Authorized User
 
Join Date: Jul 2005
Location: Exeter, , United Kingdom.
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

Reply With Quote
  #2 (permalink)  
Old July 29th, 2005, 10:17 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

'---------- 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
Reply With Quote
  #3 (permalink)  
Old July 29th, 2005, 04:32 PM
Authorized User
 
Join Date: Jul 2005
Location: Exeter, , United Kingdom.
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
Reply With Quote
  #4 (permalink)  
Old July 29th, 2005, 04:36 PM
Friend of Wrox
 
Join Date: Jan 2005
Location: Kansas City, Missouri, USA.
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
Reply With Quote
  #5 (permalink)  
Old July 29th, 2005, 06:02 PM
Authorized User
 
Join Date: Jul 2005
Location: Exeter, , United Kingdom.
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
Reply With Quote
  #6 (permalink)  
Old July 29th, 2005, 06:05 PM
Friend of Wrox
 
Join Date: Jan 2005
Location: Kansas City, Missouri, USA.
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

You're more than welcome.
Kevin

dartcoach
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
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



All times are GMT -4. The time now is 12:19 PM.


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