|
|
 |
| 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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

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

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

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

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

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
|
|
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
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |