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 August 17th, 2008, 04:04 PM
Registered User
 
Join Date: Aug 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default DoCmd.OpenForm

I am trying to open a form from an on click property on a form. I want to only include entries in the second table that match the LastName field that in on the first and second forms The problem is it always brings up an input box asking for the name and saying I want instead of the data I requested here is the code. If I input the last name I want the form opens fine with the data I requested but I want it to do it from the data in the stLinkCreteria string. I have seen so many examples of this. Why doesn't it work? I don't want to have to input the LastName value, when the data is already in the stLinkCrateria field. Frustrated.....

The request box looks like this

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Enter Parameter Value ? x|
| |
| Name (from me.lastname) |
| |
| |OK| |Cancel |
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~|

My Code..........

Private Sub Command119_Click()

 On Error GoTo Err_Command119_Click

    Dim stDocName, stLinkCriteria As String

    stDocName = "notes" 'The second form

    stLinkCriteria = "[LastName]=" & Me![LastName]

    DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command119_Click:
    Exit Sub

Err_Command119_Click:
    MsgBox Err.Description
    Resume Exit_Command119_Click

End Sub


Thanks all

 
Old August 21st, 2008, 10:02 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

First, replace

stLinkCriteria = "[LastName]=" & Me![LastName]

with

stLinkCriteria = "[LastName] = '" & Me![LastName] & "'"

Last name is text, therefore you should surround it with a delimiter... in this case, an apostrophe. It if were a date, it'd be the pound sign (#). And if a number, then you would have it as you wrote it... with nothing.

The parameter coming up sounds like your underlying table or query is has the field NAME in there, but you're passing LastName instead... so it's asking for the value of LastName. Note that NAME is a VBA reserved word. If your table or query does have NAME in a field, change it to something else.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division





Similar Threads
Thread Thread Starter Forum Replies Last Post
DoCmd Openform arguments BBWEST Access 1 August 21st, 2008 10:23 AM
DoCmd.OpenForm does not work jansb000 Access VBA 1 March 25th, 2008 06:45 AM
Docmd.Openform problem mkobulni Access VBA 7 August 29th, 2007 09:05 AM
DoCmd.OpenForm turp Access VBA 2 December 15th, 2006 08:33 AM
How does DoCmd.OpenForm work? Brian263 Access 3 November 23rd, 2004 10:32 PM





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