473,386 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

VBA-Deleting fields (Input Problem)

daoxx
32
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:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdApV_Click()
  2. Dim sql1 As String
  3. Dim c As Integer
  4. sql1 = "DELETE * FROM Cars WHERE [N_Car]='" & c & "'"
  5. c = InputBox("Insert the ID of the car you want to remove.","Remove Car")
  6. DoCmd.RunCommand (acCmdSelectAllRecords)
  7. DoCmd.RunSQL sql1
  8. Me.cCar.Requery
  9. 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 :\
Apr 1 '08 #1
5 1305
mshmyob
904 Expert 512MB
You have some minor problems with the code. Try this

Expand|Select|Wrap|Line Numbers
  1. Dim sql1 As String
  2. Dim c As Integer
  3. c = InputBox("Insert the ID of the car you want to remove.", "Remove Car")
  4. sql1 = "delete from Cars where N_Car= " & c
  5. DoCmd.RunSQL sql1
  6. Me.cCar.Requery
  7.  
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:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdApV_Click()
  2. Dim sql1 As String
  3. Dim c As Integer
  4. sql1 = "DELETE * FROM Cars WHERE [N_Car]='" & c & "'"
  5. c = InputBox("Insert the ID of the car you want to remove.","Remove Car")
  6. DoCmd.RunCommand (acCmdSelectAllRecords)
  7. DoCmd.RunSQL sql1
  8. Me.cCar.Requery
  9. 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 :\
Apr 1 '08 #2
daoxx
32
That gave me an Overflow error, but after deleting "As Integer" everything ran fine. Thanks :)
Apr 1 '08 #3
Scott Price
1,384 Expert 1GB
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
Apr 1 '08 #4
daoxx
32
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
Apr 2 '08 #5
Scott Price
1,384 Expert 1GB
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
Apr 2 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

12
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...
1
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...
22
by: Illya Havsiyevych | last post by:
Hello How easily parse VB/VBA code by VB/VBA code ? Is any ready solutions ? Thank's, illya
41
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...
6
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...
6
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...
1
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...
18
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...
16
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...
19
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/
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.