• ** There has been a recent site upgrade. Please clear your browser cache to avoid issues. **
  • New forum feature - post voting and best solution

    Check out this thread for the details: https://www.access-programmers.co.uk/forums/threads/new-forum-feature-post-voting-and-best-answer.314134/

    This new feature looks great to me! :)

  • We now have 3 forum themes

    Go for the default (light) theme, Shades of Grey or Shades of Blue. I just added the Blue one.

    The thread about it is here: https://www.access-programmers.co.uk/forums/threads/new-forum-theme-shades-of-blue.314136/

Field plus 1 (2 Viewers)

Malcolm17

Member
Local time
Today, 13:23
Joined
Jun 11, 2018
Messages
39
Hi,

I have a field in a form linked to a table called "Chase", I would like to click a button and the field would increase by 1, however I cannot work out how to do something as simple as this.

I am looking for something like:
Me.Chase = Me.Chase + 1

Malcolm
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 06:23
Joined
Aug 30, 2003
Messages
34,610
What you've posted should work. Do you get an error, or?

Edit: I assume there's a textbox by that name on the form.
 

Malcolm17

Member
Local time
Today, 13:23
Joined
Jun 11, 2018
Messages
39
Thats what I though!!

Code:
Private Sub Chase_Click()
Me.Chase = Me.Chase + 1
End Sub

Gives me the error:
Run-time error '438':
Object doesn't support this property or method

I have tried various things like:
Chase = Chase + 1
Me.Chase = (Me.Chase + 1)
 

Malcolm17

Member
Local time
Today, 13:23
Joined
Jun 11, 2018
Messages
39
Oh deer!!

I've just looked to make sure that the textbox is called Chase, I'm going to look stilly now as it is called Chased, the button is called Chase.

Well that was an enjoyable hour being frustrated - as I thought, when I name it properly in VBA my code works

Code:
Me.Chased = Me.Chased + 1

Sorry for troubling you, but thank you for your help.

Malcolm :)
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 06:23
Joined
Aug 30, 2003
Messages
34,610
You mentioned a button. Is Chase the button? You'd want to have a textbox bound to the Chase field, and you'd use the name of the textbox there.
 

Isaac

Lifelong Learner
Local time
Today, 06:23
Joined
Mar 14, 2017
Messages
2,389
Can't exactly tell from reading this what the situation is on these three, but just throwing this in, it's a very good habit (and will save you a lot of headache like this but also others), to follow this type of rule:
- if the column in the table is called Chase (and the textbox is bound to that column)
- call the textbox control txtChase
- call the button btnSomething or cmdSomething

Just don't leave the name of the controls identical to the name of the underlying table column they are bound to (controlsource). If you do so, someday you will probably write code that actually behaves differently than anticipated..because the controlsource value and the textbox value will be 2 different things, and behave in 2 different ways.
 
Last edited:

pbaldy

Wino Moderator
Staff member
Local time
Today, 06:23
Joined
Aug 30, 2003
Messages
34,610
I agree with the naming recommendation, and sadly the wizards will make the control names the same as the field names.
 

Users who are viewing this thread

Top Bottom