Results 1 to 8 of 8
  1. #1
    mainac is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2017
    Posts
    4

    Change data in database with button on forms

    I may just be dumb, but does anyone know how to change values in the database with buttons on forms. In my situation i will just want to + or - 1 to the values that are in there already.



    Sorry if i am being really dumb guys!

    Thanks

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Let's say that your command button was named Command9, and the field you want to update is Field1.
    Then add this VBA code to the Click event of the command button to add one to Field1 every time it is clicked.
    Code:
    Private Sub Command9_Click()
        Me.Field1 = Me.Field1 + 1
    End Sub

  3. #3
    mainac is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2017
    Posts
    4
    Hi, ^^ thank you. But when i run this code

    Private Sub Command0_Click()
    Me.Field2 = Me.Field2 + 1
    End Sub

    it gives me this: "compile error: Method or data member not found."

    This is in access 2016 if it changes anything.

  4. #4
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Is Field2 the name of your Field?
    Is it bound to anything?
    What data type is it?

  5. #5
    mainac is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2017
    Posts
    4
    Hi,

    Whilst i have been doing this it is.
    I dont think that it is.
    It is a Number.

  6. #6
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Are you showing Field2 on your Form?
    If it is not bound to anything, does it have any initial value (if so, where is it being set)?

  7. #7
    mainac is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2017
    Posts
    4
    ah ^^, thank you showing field 2 fixed it

  8. #8
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Yes, the "Me" reference only works if the field is on the Form.
    Note if you want to hide it from view, just change the Visible property for that field to No.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 11-13-2016, 08:15 AM
  2. Replies: 5
    Last Post: 04-01-2016, 10:08 PM
  3. Replies: 1
    Last Post: 07-01-2014, 01:41 PM
  4. Replies: 3
    Last Post: 07-29-2011, 09:30 AM
  5. Forms: Not immediate change of database
    By firlanu in forum Forms
    Replies: 5
    Last Post: 08-11-2008, 12:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums