473,320 Members | 1,939 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Simple vba problem, please help?

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
  2.  
  3. Forms![form2]!ID.Value = Me!ID.Value
  4.  
  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
3 1334
Stewart Ross
2,545 Expert Mod 2GB
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!

-Stewart
Dec 1 '08 #2
zapras
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
missinglinq
3,532 Expert 2GB
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

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

Similar topics

3
by: Patchwork | last post by:
Hi Everyone, Please take a look at the following (simple and fun) program: //////////////////////////////////////////////////////////////////////////// ///////////// // Monster Munch, example...
17
by: savesdeday | last post by:
In my beginnning computer science class we were asked to translate a simple interest problem. We are expected to write an algorithm that gets values for the starting account balance B, annual...
6
by: francisco lopez | last post by:
ok , first of all sorry if my english is not so good, I do my best. here is my problem: I don´t know much javascript so I wrote a very simple one to validate a form I have on my webpage. ...
5
by: Rob Somers | last post by:
Hey all I am writing a program to keep track of expenses and so on - it is not a school project, I am learning C as a hobby - At any rate, I am new to structs and reading and writing to files,...
0
by: Alan Silver | last post by:
Hello, I am having a problem setting and resetting cookies. I'm sure I just doing something really stupid as this is such a basic issue, but I can find any answer. Please can someone help me? ...
11
by: samuelberthelot | last post by:
Hi, I've got 3 input HTML (dropdown lists) on my page. One for selecting a Month, one for the day, one for the year. Very simple... My problem is that I'd like to update the Days one according...
15
by: gjoneshtfc | last post by:
Hello, I have a simple problem that I just cannot get my head around! I currently have the following line in my ASP recordset: Recordset1.Source = "SELECT * FROM MainTable ORDER BY Price ASC"...
1
by: Synapse | last post by:
Hello... We were asked to create a simple calculator program in our C++ subject by using loops only. i have a problem in creating a loop in the multiplication and division operation so please can...
0
DressageRider
by: DressageRider | last post by:
I need your help. Desperately. Someone has to be able to fix the utter balls up I've made after dinking around in Flash for the last four days. I have no prior knowledge of anything other than...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.