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 VBA
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 28th, 2003, 11:24 PM
Registered User
 
Join Date: Nov 2003
Location: Denver, CO, USA.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Passing values to a form

I have an unbound form with two text boxes. I want the form to open with values assigned to each box, let the user change those values and assign those new values to variables when the form is closed. I vaguely remember how to do this, but I am having trouble getting it to work. Specifically, I get an "Application-defined or object-defined error" when I try to show the form. Here is my code:

    datBeginDate = #3/1/2001#
    datEndDate = Date
    strFormName = "frm Get Dates"
    DoCmd.OpenForm strFormName, , , , , acHidden
    Forms(strFormName)!TxtBeginDate = datBeginDate
    Forms(strFormName)!txtEndDate = datEndDate
    datBeginDate = Forms(strFormName).TxtBeginDate
    datEndDate = Forms(strFormName).txtEndDate
    Forms(strFormName).show Modal

Would someone tell me what I am doing wrong? Thanks.

- Mark Schenk
Reply With Quote
  #2 (permalink)  
Old November 30th, 2003, 10:14 AM
Authorized User
 
Join Date: Jun 2003
Location: , FL, USA.
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Anywhere you have this Forms(strFormName) you need to change it to this Forms("strFormName"). That should do it for you. Also if you want the user to change the information why are you opening the form as acHidden?

Kenny Alligood
Reply With Quote
  #3 (permalink)  
Old November 30th, 2003, 03:25 PM
Registered User
 
Join Date: Nov 2003
Location: Denver, CO, USA.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the response. strFormName is not the name of the form; the form's name is "frm Get Dates". strFormName is a string variable to which I assigned the form's name. It does not make sense to me to put a variable within quotes. In other words, writing
Forms("frm Get Dates")!txtBeginDate = datBeginDate
makes sense to me, but not
Forms("strFormName")!txtBeginDate = datBeginDate.

I hide the form initially so that I can assign values to the text boxes before the user sees the form. I then make the form visible later in the code.

- Mark


Quote:
quote:Originally posted by Kenny Alligood
 Anywhere you have this Forms(strFormName) you need to change it to this Forms("strFormName"). That should do it for you. Also if you want the user to change the information why are you opening the form as acHidden?

Kenny Alligood
Reply With Quote
  #4 (permalink)  
Old November 30th, 2003, 05:35 PM
Authorized User
 
Join Date: Jun 2003
Location: , FL, USA.
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry for the initial reply. I have taken your code and put it into a working db (I also really looked at it this time) and found this possible solution. First off the last line of your code is actually generating the error //Forms(strFormName).show Modal// due to the fact that .Show is not an option in this context. What I suggest is changing that last line to look like this:

Forms(strFormName).Visible = True

It accomplishes the same thing but doesn't generate an error. As for the modal property why not just set that in the forms property sheet? If you would rather set it in code you can use this:

Forms(strFormName).Modal = True

Hope this helps you.

Kenny Alligood
Reply With Quote
  #5 (permalink)  
Old November 30th, 2003, 11:39 PM
Registered User
 
Join Date: Nov 2003
Location: Denver, CO, USA.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, Kenny. Actually, I solved the problem with this form by setting default values in the form itself. That way, I do not have to start the form hidden. Your suggestion will come in handy, however, for the next part of my application where I do have to pass values to the form before displaying it.
I noticed that Show was not one of the options presented for this form. I am confused about the difference between Show and Visible. Maybe someone can enlighten me.
What really goads me is that I wrote four applications in Access anywhere from four to ten years ago. Now, I cannot remember the first thing about it. Must be that "oldtimers" disease.

- Mark

Quote:
quote:Originally posted by Kenny Alligood
 Sorry for the initial reply. I have taken your code and put it into a working db (I also really looked at it this time) and found this possible solution. First off the last line of your code is actually generating the error //Forms(strFormName).show Modal// due to the fact that .Show is not an option in this context. What I suggest is changing that last line to look like this:

Forms(strFormName).Visible = True

It accomplishes the same thing but doesn't generate an error. As for the modal property why not just set that in the forms property sheet? If you would rather set it in code you can use this:

Forms(strFormName).Modal = True

Hope this helps you.

Kenny Alligood
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
passing Multidimensional Array Values back to form stitch Classic ASP Databases 2 June 21st, 2013 01:59 PM
Passing Form Values in ASP.Net sankar General .NET 10 September 21st, 2006 11:13 AM
Passing form values from 1 frame to another. edkeyte Javascript How-To 4 February 2nd, 2004 12:33 PM
Passing Values from a Form to another Louisa Beginning VB 6 1 September 2nd, 2003 07:56 AM



All times are GMT -4. The time now is 05:58 AM.


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