Simple vba problem, please help?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zapras
    New Member
    • Dec 2008
    • 4

    Simple vba problem, please help?

    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..
    Code:
    DoCmd.openform "form2", acNormal, , , acFormAdd
    
    Forms![form2]!ID.Value = Me!ID.Value
    
    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 :(
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

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

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

    Comment

    • zapras
      New Member
      • Dec 2008
      • 4

      #3
      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 :)

      Comment

      • missinglinq
        Recognized Expert Specialist
        • Nov 2006
        • 3533

        #4
        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)>

        Comment

        Working...