Solved

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

Posted on 2003-11-19
5
323 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Or better still use it as static:

Static july As Integer
0
 
LVL 44

Expert Comment

by:Arthur_Wood
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
matchUp  challenge 9 71
VBA color chart bars 12 64
strCopies  challenge 17 73
listing all functions in JavaScript 19 96
Purpose To explain how to place a textual stamp on a PDF document.  This is commonly referred to as an annotation, or possibly a watermark, but a watermark is generally different in that it is somewhat translucent.  Watermark’s may be text or graph…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now