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?
 
SNilssonCommented:
Or better still use it as static:

Static july As Integer
0
 
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
0
 
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.
0
 
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
0
 
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.