Newbie: Delete Records form Database, Update from Listbox 
Author Message
 Newbie: Delete Records form Database, Update from Listbox

The code below looks good but doesn't
:(  

Any help will be appreciated!

                               Magic

    'DELETE all records from database that match wsSSN
    Dim strSQL As String
    Dim strSSN As String
    strSSN = Trim(wsSSN)
    strSQL = "DELETE * FROM tblEmpInsPlans WHERE emp_ssn= " & "'" & strSSN & "'"
    Data3.Database.Execute strSQL

    'Update tblEmpInsPlans from ListBox
    Dim i As Integer
    For i = 0 To List1.ListCount - 1
        wsString = List1.Text
        rs3.AddNew
        rs3.Fields("Emp_SSN") = wsSSN
        rs3.Fields("Ins_Plan") = wsString
        rs3.Update
    Next
    Data3.Refresh



Sat, 28 Aug 2004 06:41:32 GMT  
 Newbie: Delete Records form Database, Update from Listbox
Magic:
A quick look shows your field names with different cases: lower in one and
upper in another. ????

SCA


Quote:
> The code below looks good but doesn't
> :(

> Any help will be appreciated!

>                                Magic

>     'DELETE all records from database that match wsSSN
>     Dim strSQL As String
>     Dim strSSN As String
>     strSSN = Trim(wsSSN)
>     strSQL = "DELETE * FROM tblEmpInsPlans WHERE emp_ssn= " & "'" & strSSN
& "'"
>     Data3.Database.Execute strSQL

>     'Update tblEmpInsPlans from ListBox
>     Dim i As Integer
>     For i = 0 To List1.ListCount - 1
>         wsString = List1.Text
>         rs3.AddNew
>         rs3.Fields("Emp_SSN") = wsSSN
>         rs3.Fields("Ins_Plan") = wsString
>         rs3.Update
>     Next
>     Data3.Refresh



Sat, 28 Aug 2004 11:40:07 GMT  
 Newbie: Delete Records form Database, Update from Listbox


<snip>
You forgot to say what is wrong with it ?  

Quote:
>    'Update tblEmpInsPlans from ListBox
>    Dim i As Integer
>    For i = 0 To List1.ListCount - 1
>        wsString = List1.Text

You're pulling  .Text form the listbox here.  
What you want is..
        wsString = List1.List(i)

Was this the problem ?

Regards, Frank



Sat, 28 Aug 2004 11:42:53 GMT  
 Newbie: Delete Records form Database, Update from Listbox
Hi Frank,  I'm trying to:

First, delete all records in the database that
have the same field "EMP_SSN" as the variable wsSSN.

Second, to addnew to the database, all items in the ListBox.

The code below looks good but doesn't
:(  

Any help will be appreciated!

                               Magic

Quote:



> <snip>
> You forgot to say what is wrong with it ?  

> >    'Update tblEmpInsPlans from ListBox
> >    Dim i As Integer
> >    For i = 0 To List1.ListCount - 1
> >        wsString = List1.Text

> You're pulling  .Text form the listbox here.  
> What you want is..
> wsString = List1.List(i)

> Was this the problem ?

> Regards, Frank



Sat, 28 Aug 2004 20:27:11 GMT  
 Newbie: Delete Records form Database, Update from Listbox
Quote:
>  strSQL = "DELETE * FROM tblEmpInsPlans WHERE emp_ssn= " & "'" & strSSN &

"'"

i don't know about other databases, but in SQL server 7, you would have to
get rid of the *

-sean



Mon, 30 Aug 2004 10:09:25 GMT  
 Newbie: Delete Records form Database, Update from Listbox
This is correct.  The docs are wrong; you must get rid of
the * from DELETE *.  Been there, cursed that.

Joe

Quote:

> >  strSQL = "DELETE * FROM tblEmpInsPlans WHERE emp_ssn= " & "'" & strSSN &
> "'"

> i don't know about other databases, but in SQL server 7, you would have to
> get rid of the *

> -sean



Mon, 30 Aug 2004 10:16:39 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Newbie: Delete Records form Database, Update from Listbox

2. Newbie: Delete blocks of records from the database

3. Newbie: Delete blocks of records from the database

4. newbie help please - update a record in a database

5. newbie help please - update a record in a database

6. Newbie Database record update question

7. Cannot delete records form a MDB database

8. Deleting records from a recordset without deleting from the database

9. Updating a single OLE link for a record OR updating existing database

10. Deleting Records in a ListBox.

11. Updating records on Database #1 from another database #2

12. Cannot delete record from Listbox

 

 
Powered by phpBB® Forum Software