how change fields programmatically ?

sarkis

Registered User.
Local time
Today, 13:00
Joined
Mar 15, 2012
Messages
10
Hi all,
I am beginner and may be my question is stupid but I cannot do that.
So, I have a table - Table1,
a numeric field - id1
A form Form1 ,on the form label- Label1 which shows Field1 value
(instead of Label may be another control)
a button -Button1.
I need to increase Field1 value by 1 when Button 1 clicked.
I tried following but there is no any reaction when I clicked the button.

Private Sub mCommand1_Click()
[Table1]![id1] = [Table1]![id1] + 1
End Sub

Thanks for answers
 
Try this:

me.YourFieldName=me.YourFieldName+1

If the datatype is Autonumber, this will fail.
 
Thanks for answer.
But It doesn't work still.
There is no any reaction no errors.
It seems me that code is not even calling.
and I need to change tables value ,not only on the form.
Should it change the fields value if we change the controls value?
 
Did you change "YourFieldName" to whatever your control is called? Is the name of the button "mCommand1"? Did you actually click the button?
 
Here is the code.

Private Sub mCommand1_Click()
Me.id1 = Me.id1 + 1
End Sub

I tried to debug,
(I put a debug sign behind the code line )
but it seems click event didn't happen.
I change label to textbox end it shoes values.
 
Use a text box and make sure the text box's control source is id1.
 
I did it and text box control works.
But I don't need to change value with a text box control.
Even if it is a text box control ,it should be read only and value of the field should be changed only by click event.
 
Last edited:
So your telling me that it works, but you don't want to be able to change the value via the text box? If so, there are many things you can do. You can set the text box's visible property to false, or you can play with the enabled property and the locked property.
 
text box works ,but click event doesn't.
I need to work click event.
 
Thank you for your patient.
But your code doesn't work.
It doesn't increase the id1 value.
 
Make sure that your database is in a Trusted Location otherwise no VB coe will run.
 
Thank you for respond.
I understand what was a problem.
Actually records are changing ,but it doesn't appear in the form.
The form is need to be "refreshed" or make some change the record position on the table.
(I don't know how to do that)
Anyway thanks again
 
Why are you wasting peoples time with two threads on virtually the same problem.

Further instances of double posting are liable to be treated as SPAM and incur all the attendant penalties :mad:
 
Not for me it doesn't. I'm really not sure why it would be any different for you.
 

Users who are viewing this thread

Back
Top Bottom