Solved

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

Posted on 2003-11-19
5
325 Views
Last Modified: 2010-05-18
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.
0
Comment
Question by:matt_fennell
5 Comments
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 9779916
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
 

Author Comment

by:matt_fennell
ID: 9780046
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
 
LVL 10

Expert Comment

by:D_M_D
ID: 9781759
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
 
LVL 8

Accepted Solution

by:
SNilsson earned 20 total points
ID: 9782339
Or better still use it as static:

Static july As Integer
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 9783194
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

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question