473,394 Members | 1,781 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,394 software developers and data experts.

Problem deleting record

I keep getting a Run-Time everytime I try deleting a record: My code is this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdDelete_Click()
  2. Dim sql As String
  3. sql = "Delete * from Agentinfo where AGENTID =" & txtAgtId.Text 
  4. MsgBox (sql)
  5. Dim cn As New ADODB.Connection
  6. cn.ConnectionString = "DSN=Agents"
  7. Dim rs As New ADODB.Recordset
  8. cn.Open
  9. Set rs = cn.Execute(sql)
  10. MsgBox ("Record successfully deleted")
  11. txtAgtId.Text = ""
  12. txtBranch.Text = ""
  13. txtFirstName.Text = ""
  14. txtLastName.Text = ""
  15. txtDateHired.Text = ""
  16. txtStatus.Text = ""
  17. cn.Close
  18. End Sub
But I am getting an error message saying "Too Few Parameters. Expected 1"
Mar 22 '08 #1
7 1292
mafaisal
142 100+
Hello

Try This

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim sql As String
  3. sql = "Delete  from Agentinfo where AGENTID =" & txtAgtId.Text 
  4. MsgBox (sql)
  5. Dim cn As New ADODB.Connection
  6. cn.ConnectionString = "DSN=Agents"
  7. cn.Open
  8. cn.Execute(sql)
  9. MsgBox ("Record successfully deleted")
  10. txtAgtId.Text = ""
  11. txtBranch.Text = ""
  12. txtFirstName.Text = ""
  13. txtLastName.Text = ""
  14. txtDateHired.Text = ""
  15. txtStatus.Text = ""
  16. cn.Close
  17.  
  18.  
  19.  
Also When U Post Question Clearly Specify Which Location Error is coming

So Here Experts Have easily identify that

Faisal
Mar 22 '08 #2
I keep getting a Run-Time everytime I try deleting a record: My code is this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdDelete_Click()
  2. Dim sql As String
  3. sql = "Delete * from Agentinfo where AGENTID =" & txtAgtId.Text 
  4. MsgBox (sql)
  5. Dim cn As New ADODB.Connection
  6. cn.ConnectionString = "DSN=Agents"
  7. Dim rs As New ADODB.Recordset
  8. cn.Open
  9. Set rs = cn.Execute(sql)
  10. MsgBox ("Record successfully deleted")
  11. txtAgtId.Text = ""
  12. txtBranch.Text = ""
  13. txtFirstName.Text = ""
  14. txtLastName.Text = ""
  15. txtDateHired.Text = ""
  16. txtStatus.Text = ""
  17. cn.Close
  18. End Sub
But I am getting an error message saying "Too Few Parameters. Expected 1"
Thanks for your information, I am new to this forum, however when I tried the code you gave me, I am getting a new error:
Run-time error '-2147217904 (80040e10)': Microsoft [ODBC Microsoft Access Driver] Syntax error in string in query expression 'AGENTID = A04123"
Mar 22 '08 #3
Thanks for your information, I am new to this forum, however when I tried the code you gave me, I am getting a new error:
Run-time error '-2147217904 (80040e10)': Microsoft [ODBC Microsoft Access Driver] Syntax error in string in query expression 'AGENTID = A04123"

--------------------------------------------------------------------------------
Mar 22 '08 #4
Thanks for your information, I am new to this forum, however when I tried the code you gave me, I am getting a new error:
Run-time error '-2147217904 (80040e10)': Microsoft [ODBC Microsoft Access Driver] Syntax error in string in query expression 'AGENTID = A04123"
change your query :
sql = "Delete * from Agentinfo where AGENTID =" & txtAgtId.Text
with
sql = "Delete * from Agentinfo where AGENTID = '" & txtAgtId.Text & "'"
Mar 23 '08 #5
obkfixx
19
Try this:

Private Sub cmdDelete_Click()

Dim cn As New ADODB.Connection

cn.ConnectionString = "DSN=Agents"

Dim rs As New ADODB.Recordset
cn.Open

Set rs = cn.Execute( "Delete * from Agentinfo where AGENTID = '"& txtAgtId.Text &"'")
MsgBox ("Record successfully deleted")
txtAgtId.Text = ""
txtBranch.Text = ""
txtFirstName.Text = ""
txtLastName.Text = ""
txtDateHired.Text = ""
txtStatus.Text = ""
cn.Close
End Sub
Mar 23 '08 #6
lotus18
866 512MB
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdDelete_Click()
  2. Dim sql As String
  3. sql = "Delete * from Agentinfo where AGENTID=" & txtAgtId.Text 
  4. MsgBox (sql)
  5. Dim cn As New ADODB.Connection
  6. cn.ConnectionString = "DSN=Agents"
  7. cn.Open
  8. cn.Execute(sql)
  9. MsgBox ("Record successfully deleted")
  10. txtAgtId.Text = ""
  11. txtBranch.Text = ""
  12. txtFirstName.Text = ""
  13. txtLastName.Text = ""
  14. txtDateHired.Text = ""
  15. txtStatus.Text = ""
  16. cn.Close
  17. End Sub
What is the datatype of AGENTID?

Rey Sean
Mar 23 '08 #7
mafaisal
142 100+
Hello

Try This
Expand|Select|Wrap|Line Numbers
  1. Dim sql As String
  2. sql = "Delete *  from Agentinfo where AGENTID ='" & txtAgtId.Text & "'"    '*** " & txtAgentid  - Change to  '" & txtAgentID & "'
  3. MsgBox (sql)
  4. Dim cn As New ADODB.Connection
  5. cn.ConnectionString = "DSN=Agents"
  6. cn.Open
  7. cn.Execute(sql)
  8. MsgBox ("Record successfully deleted")
  9. txtAgtId.Text = ""
  10. txtBranch.Text = ""
  11. txtFirstName.Text = ""
  12. txtLastName.Text = ""
  13. txtDateHired.Text = ""
  14. txtStatus.Text = ""
  15. cn.Close
  16.  
  17.  
in Ur code AgentId as Integer in Line 2

I think AgentId is Text(String) Bcoz in ur code agentid = A04123
Also Check ur table if AgentId is Number or text
if Number u given text is not number that is string thats problem
check
if number change query to
Expand|Select|Wrap|Line Numbers
  1. sql = "Delete *  from Agentinfo where AGENTID =" & val(txtAgtId.Text)
  2.  
Try ablove code

Faisal

Thanks for your information, I am new to this forum, however when I tried the code you gave me, I am getting a new error:
Run-time error '-2147217904 (80040e10)': Microsoft [ODBC Microsoft Access Driver] Syntax error in string in query expression 'AGENTID = A04123"
Mar 23 '08 #8

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

Similar topics

1
by: Mark | last post by:
This question refers to a main form with a continuous form subform. After an error occurs after entering several records in the subform, how can I delete all the data in the main form and all the...
3
by: Nathan Bloom | last post by:
Hi, I have a data entry form (access 2000) that also allows the user to add, update, and delete records from the form. The Delete action is carried out in an event procedure and has the...
2
by: uv | last post by:
Hi! I'm having problems submitting a new record through the form. I'm working with the wizard and I've added a control button to my form for entering entering a new record but for some reason it...
1
by: KC | last post by:
Hello, I am using Access 2002. WinXP, Template from MS called Orders Mgmt DB. I have tweaked this DB to work for our small co. It has worked pretty well up until I made the mistake of deleting...
3
by: deekay | last post by:
I'm using Access 2000 working in DAO at the moment and am having trouble deleting a record from a form that has been filtered. So I'm filtering a form and then when the user selects the record...
0
by: Lisa Jones | last post by:
Hi Has anyone see this problem in ADO.Net when deleting a record (assuming that the table has identity increment Index) result in getting wrong index key if right after adding the record the table...
10
by: A_PK | last post by:
I am writing mobile application using Vb.net when i click the last row of list view, and try to delete it.... will promtpy the following message "Additional information:...
46
by: DP | last post by:
hi, i've got a form, with a subform in it. i've got a delete button in the subform. the code i;ve got is; Private Sub cmdDeleteRecord_Click() msg = "Are you sure you want to delete this...
4
by: sphinney | last post by:
I'm not exactly sure how to start this post. My question is pretty simple, but it will take a little bit of context before I can state it. (And thanks in advance for taking the time to read this!) ...
1
by: Kyosuke18 | last post by:
Hi everyone, I have a problem in deleting a data that is connected on the database.. I tried this code but it shows me an error: Run-time error '-2147217900(80040e14)': Syntax error in string in...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.