Simple adding code. Not sure why I am getting a type mis match error

Have got a simple piece of code which keeps a running total of visits to companies. Have dimensioned the text box as integer but keep getting type mismatch error and dont understand why.

Dim july As Integer
Text8.Text = july

Data1.Recordset.Edit
july = july + 1
Data1.Recordset.Update

I have tried different combinations of this code. I either seem to get a type mismatch error or it simply just doesn't add.
matt_fennellAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Arthur_WoodCommented:
all you are doing is incrementing the value of a variable, called july.  Editing the recordset does NOT, in any way, shape or form, cause the variable to be used in that recordset.


How does this code 'keep' a running total?

The way this code is wriiten, you create a varaibel, called july, which happens to be an Integer type (so when it is first created, it is assigned the default value 0).  You then assign the value of the variable july (which equals 0 at that point) to the Text of a TextBox control, named Text8.  SO now, Text8 displayes the value 0.

you then call the Edit method of the Recordset object associated with a DataControl, named Data1 (this does NOTHING to The variable 'july', or to the TextBox Text8).

You then Add 1 to the variable 'july' (so its value is now 1), but that also does NOTHING to the TextBox (which still shows the value 0).  This also does NOTHING to the Recordset, or the datacontrol for that matter. (The recordset has PRECISELY the same contents that it had BEFORE any of this code executed).  You then call the Update method of the Recordset (which would NORMALLY cause any CHANGES made to the recordset - but there HAVE BEEN NO CHANGES- to be written back to the table from which the recordset was originally retrieved).  But as I just said, there have been no changes, so NOTHING happens to the recordset, or to the table associated with the recordset.

What EXACTLY are you trying to do, with this code, and where is this being executed - in a CLICK event handler of a Button, for instance.

AW
matt_fennellAuthor Commented:
The code is stored in a command button. When clicked I wish for the text box to add one to its original number. In the case of starting from scratch, as the default value is 0, when the button is clicked I would like a one to appear and be text box and also be stored in the database.
D_M_DCommented:
Here you go... This will properly increment july
Make july global

Dim july As Integer

Private Sub Command1_Click()

Data1.Recordset.Edit
july = july + 1
Data1.Recordset.Update

Text8.Text = july
End Sub

Private Sub Form_Load()
' on form load set the textbox
Text8.Text = july
End Sub

--------
D_M_D
SNilssonCommented:
Or better still use it as static:

Static july As Integer

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Arthur_WoodCommented:
but even so, this block:

Data1.Recordset.Edit
july = july + 1
Data1.Recordset.Update

DOES NOTHING other than incrementing the varaible 'july'.  Nothing is ever saved, permanently.  

What do you THINK you are doing with the Recordset, in this code?

AW
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.