Full Version: NEED to populate textbox values from a different form or functio
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
mcsd1
I have a form with a list box that shows a list of requests that are unassigned.

When you double click on the list box, I want a different form to open. All of the text boxes on the second form are unbound. I want to specifically set the value of each field, but Access won't let me use the word me!

For example, if I were trying to do this all within the same form, I can use the code below:

me.txt_request_id = !Request_ID


How do I do this from a different form?
The Visual Basic help says I should be able to use this code but it doesn't work:

Forms!NAME_OF_FORM.Controls!txt_request_ID.text = "Some Value"

I've tried every variation of this that I can think of and nothing works!! Please help! I am building this database for work and I'm already behind schedule. I've looked in every Access book I have and can't find anything that will work!
freakazeud
Hi,
welcome to UA forums.
Check this FAQ for reference issues.
If you execute this from the form with the listbox on it then the code would be:

Forms!YourOtherForm.YourOtherFormsControl = "Some Value"

HTH
Good luck
mcsd1
No luck freakazeud!!

From the listbox form I first opened the other form (Named Assignment_Form) with this line:

DoCmd.OpenForm "Assignment_Form", acNormal


Then I tried this:
MsgBox Forms!Assignment_form.txt_Request_ID

I get the error: "Method 'Item' of Object 'Forms' failed"

I also tried:
MsgBox Forms!Assignment_form.txt_Request_ID.text
MsgBox Forms!Assignment_form.txt_Request_ID.value

No Luck!
freakazeud
Try to wrap you names in square brackets:

Forms![Assignment_form]![txt_Request_ID]

Make sure the form is open when you call this.
HTH
Good luck
mcsd1
Thanks freakazeud, but still no luck.

I get the same error: "Method 'Item' of Object 'Forms' failed"
freakazeud
Can you attach an example db so I can take a look at it?
HTH
Good luck
jmcwk
Freak,

Could be mis reading the posters request but could it be that:

The form opening the form to be opened is closed?
The Expressions are not on the form to be opened?

Just A Thought
mcsd1
It won't let me attach the database. I tried just changing the extension to .jpg. I don't know if you'll be able to convert it back to .mdb.

The Main form I am working with is "Unassigned_Request_Search". This form has the list box.

When you double click it, I am passing the value of the Request_ID to a Public Function called "Open_Assignment_Form(Req_ID As String)".

Then within the public function I am opening the second form called "Assignment_Form". That's where I get stuck. I added some notes to the code!

Thanks for taking a look at this!
freakazeud
You have to zip up the mdb file and it has to be under 500kb (do a compact and repair if it is too big or take some stuff out).
As I mentioned before the form has to be opened when you call this AND you are doing this from the form which holds the listbox. With that info and the syntax I gave you it should work.
jmcwk
Attachment needs to be Zipped and attached with a .zip extension no larger than 500000kb
HTH
mcsd1
Ok, let's try to attach this again!
mcsd1
There we go! I got it to attach.

John/jmcwk - Yes, both forms are open.

Freakazeud - I tried it both from the Public Function, and from the Unassigned_Request_Search form. I get the same error.
freakazeud
Hi,
something is wrong with your database. I imported your two forms and the module and tried it and it worked as supposed to. So try to import your objects into a new blank db. Maybe some dll broke and messes things up because the syntax is all correct. You don't need to do this in a seperate module by the way. Just do it on the double click event.
HTH
Good luck
mcsd1
Thanks, I'll try that! I am heading to the Dentist for the rest of this afternoon. sad.gif


Do you think it could be a reference issue? Can you tell me what you have referenced?

I currently have:
Visual Basic for Applications
Microsoft Access 11.0 Object Library
OLE Automation
Microsoft DAO 3.6 Object Library
Microsoft ActiveX Data Objects 2.1 Library
freakazeud
There is a possibility that it is a reference issue.
The references seem fine, but they might be broken somehow. So try the import as I did and see if the syntax works then, because it didn't throw an error for me anymore afterwards.
HTH
Good luck
mcsd1
It worked!

I imported all of my objects into a new db, and it appears to be working fine now!

I double checked the references, and everything was the same. I'm not sure what caused this, but at least it is working now!

Thanks a ton for all of your help!
freakazeud
You're welcome.
Yeah like I said the references seemed fine, but maybe something just went haywire with them.
Glad you got it sorted out.
Good luck on future projects!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.