Field plus 1 (1 Viewer)

Malcolm17

Member
Local time
Today, 02:19
Joined
Jun 11, 2018
Messages
107
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
Yesterday, 19:19
Joined
Aug 30, 2003
Messages
36,118
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, 02:19
Joined
Jun 11, 2018
Messages
107
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, 02:19
Joined
Jun 11, 2018
Messages
107
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
Yesterday, 19:19
Joined
Aug 30, 2003
Messages
36,118
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
Yesterday, 19:19
Joined
Mar 14, 2017
Messages
8,738
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
Yesterday, 19:19
Joined
Aug 30, 2003
Messages
36,118
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