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 February 10th, 2007, 04:34 PM
Authorized User
 
Join Date: Feb 2007
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default Forms

I am attempting to create several forms for my database. The frmMain form will have access to all of the records from my tblData. However, I would like to then go to a 2nd form filtered by an account number or customer name from frmMain form. What would be the best way to go about this? Thanks.

 
Old February 12th, 2007, 08:46 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Send the criteria on a button click event.

There are sooooooo many posts on how to do this.

How are you selecting the data to filter your results? Is it a text field or an integer field?


mmcdonal
 
Old February 12th, 2007, 04:54 PM
Authorized User
 
Join Date: Feb 2007
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Currently the data field is a number, long integer.

 
Old February 12th, 2007, 06:43 PM
Authorized User
 
Join Date: Feb 2007
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is how I was able to do it with the help of the command wizard.
I'm trying to understand the linking/filtering logic.

Private Sub cmdUnderwriting_Click()
On Error GoTo Err_cmdUnderwriting_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmUnderwriting"

    stLinkCriteria = "[txtAccountNumber]=" & Me![txtAccountNumber]
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Call Close_AccountData
    Form_frmAccountData.Refresh
    Form_frmAccountData.Requery

Exit_cmdUnderwriting_Click:
    Exit Sub

Err_cmdUnderwriting_Click:
    MsgBox Err.Description
    Resume Exit_cmdUnderwriting_Click

End Sub

 
Old February 13th, 2007, 08:47 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

If you read the DoCmd line as part command, part query parameter, it makes sense. In pseudo code the line says:

Open form frmUnderWriting, but limit the records to WHERE txtAccountNumber is equal to the txtAccountNumber currently displayed on this form.

Consider the underlying SQL statement to be:

SELECT *
FROM (the table you are basing frmUnderWrting on)
WHERE txtAccountNumber = Some Value from the first form

Let's say the txtAccountNumber (which is an Integer, by the way and should not be prefixed with "txt") is 8, and the table the frmUnderWriting is based on is called tblUnderWriting.

SELECT *
FROM tblUnderWriting
WHERE [txtAccountNumber] = 8

That is basically what is going on with the code.




mmcdonal
 
Old February 13th, 2007, 10:32 AM
Authorized User
 
Join Date: Feb 2007
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That makes more sense. Thank you for your help.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Forms and Sub forms Mink Access 1 December 1st, 2004 08:38 AM
Opening forms from other forms Paulsh Access VBA 1 September 30th, 2004 06:54 PM





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