By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,860 Members | 1,270 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,860 IT Pros & Developers. It's quick & easy.

Simple vba problem, please help?

P: 4
I need some help pretty please? :confused:
Im very new to vba access and been trying to work out this problem for a couple of hours. It's probably simple for other people to see the problem though. (I copied it from vba in access for dummies book) This is my code..
Expand|Select|Wrap|Line Numbers
  1. DoCmd.openform "form2", acNormal, , , acFormAdd
  3. Forms![form2]!ID.Value = Me!ID.Value
  5. DoCmd.Close acForm, "form3", acSaveYes
I have this in a click event on one form called form3. Im wanting it to open up form2 and go to the same record that form3 is on and then close form3. Simple enough but it comes up with an error saying "you can not assign a value to this object" I've done some debugging and the line "Forms![form2]!ID.Value" is at fault. The other parts are fine.

Can someone help please? Im at the end of the road here :(
Dec 1 '08 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 2.5K+
P: 2,545
Hi. Your code is trying to change a record in the other form by assigning a value to the ID field. I'd guess that your ID field is an autonumber type, which cannot be set or changed by the user. This is just as well, because you don't really want to overwrite whatever is in that field every time you open the form by clicking on the button in form 3.

You need instead to apply a filter to your form when you open it. The filter will restrict the record shown to the one that matches the ID listed. Remove the assignment line from your code, and change the OpenForm one to

Expand|Select|Wrap|Line Numbers
  1. DoCmd.openform "form2", , , "[ID] = " & Me!ID
Note that the form's Add mode, which you were using in the version posted, would only have let you add new records, not edit existing ones. I have removed it from the OpenForm call above.

Also, the Value property is the default for any control - it can be left off the reference to the control without any problem (as shown above).

Welcome to Bytes!

Dec 1 '08 #2

P: 4
Thankyou! I was reading the book Access VBA Programming For Dummies and i copied the example from it and modified it a bit. I tryed to copy it to match just like in the book. Turns out i should read the whole book first and then try to modifiy examples!
Looking forward to learning vba :)
Dec 1 '08 #3

Expert 2.5K+
P: 3,532
As Homer Simpson would say "Doh!"

Congratulations! You've learned an important lesson early; Learn the Basics! This is probably the single most obvious failing we see here on this site! People don't bother to learn the ABCs!

Once you do this, you can ask intelligent questions, and people here are 100 times more likely to answer your questions!

After doing this, when you have questions, come back and see us!

Welcome to Bytes!

Linq ;0)>
Dec 1 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.