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 14th, 2008, 02:01 PM
Registered User
 
Join Date: Aug 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default DoCmd Openform arguments

I want to open a form from another form just by pressing a button called "Notes" That will display notes with only the last name of the displayed perdon on the first form.
I placed the last name of a person into a string variable called glastname. Using the

Dim stDocName, GastName As String
gLastName = Me.Lastname ' get the Last name from the current form
stDocName = "notes" 'the form to open

This does not work Why?
    DoCmd.OpenForm stDocName, , , "LastName = gLastName"

This does
    DoCmd.OpenForm stDocName, , , "LastName = 'Book'" 'Book is a name taken from the table I am displaying.

It does not seem that GLastName is getting through to the openForm function. How do I get this to work.

Thanks I would appreciate any help you can give.

Bill



 
Old August 21st, 2008, 10:23 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

You did not include the delimiters for the last name, nor did you seperate it out as a variable.

DoCmd.OpenForm stDocName, , , "[LastName] = '" & gLastName & "'"

When writing SQL conditions, strings are surrounded by apostrophes and dates by the pound sign (#). Numbers get nothing. Other Examples:

For a date: DoCmd.OpenForm stDocName, , , "[DateOfBirth] = #" & gDOB & "#"

For a number: DoCmd.OpenForm stDocName, , , "[NoOfDependants] = " & gDependants

For a boolean (yes/no/true/false): DoCmd.OpenForm stDocName, , , "[ActiveRecord] = " & gActive


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





Similar Threads
Thread Thread Starter Forum Replies Last Post
DoCmd.OpenForm BBWEST Access 1 August 21st, 2008 10:02 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.