Hi
I've a table and a form. The table is named Cars and it has a field N_Car, which is where a ID number is stored (made of 5 digits, 12345).
cCar is a combo box with the car IDs listed.
I have this in a button on the form: - Private Sub cmdApV_Click()
-
Dim sql1 As String
-
Dim c As Integer
-
sql1 = "DELETE * FROM Cars WHERE [N_Car]='" & c & "'"
-
c = InputBox("Insert the ID of the car you want to remove.","Remove Car")
-
DoCmd.RunCommand (acCmdSelectAllRecords)
-
DoCmd.RunSQL sql1
-
Me.cCar.Requery
-
End Sub
It gets me an Overflow error. If I do "Dim c" (without "As Integer" it asks me for a parameter, when I've already input it with the input box.
Please help me :\
5 1305
You have some minor problems with the code. Try this -
Dim sql1 As String
-
Dim c As Integer
-
c = InputBox("Insert the ID of the car you want to remove.", "Remove Car")
-
sql1 = "delete from Cars where N_Car= " & c
-
DoCmd.RunSQL sql1
-
Me.cCar.Requery
-
Make sure in the future you ask for your variable before you create the SQL string.
cheers,
Hi
I've a table and a form. The table is named Cars and it has a field N_Car, which is where a ID number is stored (made of 5 digits, 12345).
cCar is a combo box with the car IDs listed.
I have this in a button on the form: - Private Sub cmdApV_Click()
-
Dim sql1 As String
-
Dim c As Integer
-
sql1 = "DELETE * FROM Cars WHERE [N_Car]='" & c & "'"
-
c = InputBox("Insert the ID of the car you want to remove.","Remove Car")
-
DoCmd.RunCommand (acCmdSelectAllRecords)
-
DoCmd.RunSQL sql1
-
Me.cCar.Requery
-
End Sub
It gets me an Overflow error. If I do "Dim c" (without "As Integer" it asks me for a parameter, when I've already input it with the input box.
Please help me :\
That gave me an Overflow error, but after deleting "As Integer" everything ran fine. Thanks :)
Deleting 'As Integer' defaults to a Variant data type for your variable. The overflow error comes because you were getting a result which exceeded the range for which the Integer data type is valid (-32,767 to 32,766 more or less). It's a better programming practice to specifically type cast your variables, rather than letting VBA 'choose' which is what happens with the Variant...
Making it a Long data type should take care of the overflow error.
Regards,
Scott
Okay, thank you for teaching me something new :D
Deleting 'As Integer' defaults to a Variant data type for your variable. The overflow error comes because you were getting a result which exceeded the range for which the Integer data type is valid (-32,767 to 32,766 more or less). It's a better programming practice to specifically type cast your variables, rather than letting VBA 'choose' which is what happens with the Variant...
Making it a Long data type should take care of the overflow error.
Regards,
Scott
Not a problem :-)
I usually err on the side of 'too much' information rather than too little, but usually there's a little bit of good in it.
Regards,
Scott
Sign in to post your reply or Sign up for a free account.
Similar topics
by: guy lateur |
last post by:
Hi all,
I am trying to write some code (macro's, if you like) to glue together
our Office applications (mainly Word, Excel and Outlook). We have a lot
of different projects going on...
|
by: Igor Mendizabal |
last post by:
Hello
We have a VB6 application that integrates an VBA IDE from which the final
user can make modifications.
We want to pass the application to VB.NET, and the first step, before
rethinking...
|
by: Illya Havsiyevych |
last post by:
Hello
How easily parse VB/VBA code by VB/VBA code ?
Is any ready solutions ?
Thank's,
illya
|
by: Matt Alanzo |
last post by:
Our SOHO 2 person compay sells furniture (not programmers). In '98 we
paid $,$$$ for a VBA -Access '97 accounting application, including VBA
source code .... an huge investment for us then (and...
|
by: Terry Bell |
last post by:
We've had a very large A97 app running fine for the last seven years.
I've just converted to SQL Server backend, which is being tested, but
meanwhile the JET based version, running under terminal...
|
by: Ieuan |
last post by:
Hello all and Happy New Year,
I've been having this problem for some time and thought I'd try to see
if anyone else out there has had the same problem or can give a little
help.
I'm using a...
|
by: Igor Mendizabal |
last post by:
Hello
We have a VB6 application that integrates an VBA IDE from which the final
user can make modifications.
We want to pass the application to VB.NET, and the first step, before
rethinking...
|
by: Ann Scharpf via AccessMonster.com |
last post by:
I am not sure which would be the best place to post this question, so I'm
posing it here with Access general questions. I have reached the point many
times in Word and in Access where my ignorance...
|
by: Sathyaish |
last post by:
I am expecting a VBA code module in one of the VBA apps, but much to my
astonishment, I don't seem to find my way through it. It seems like I
am looking at a fully compiled binary.
I have an MDB...
|
by: DesCF |
last post by:
What are the differences between vb, vb.net, & vba ?
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |