Results 1 to 17 of 17

Thread: Listbox Database

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2004
    Posts
    220

    Listbox Database

    Hi
    Firstly I have a listbox and I want the user to select an item from the list box and then click cmdStartStop

    when cmdStartStop is pressed i want it to put "Not Running" into the field Live WHERE the Campaign_Name is = to the lstnotrunning.text

    I am trying to put the variable Not Running Select into the **Insert NotRunningSelect** but it doesn't alow me to

    VB Code:
    1. Dim NotRunningSelect As String
    2. NotRunningSelect = lstNotRunning.Text
    3. If cmdStartStop.Caption = "Stop Campaign" Then
    4. NotRunning.Source "Select * From T_Campaigns WHERE Campaign_Name = **Insert NotRunningSelect** "
    5. NotRunning.Open , db, adOpenKeyset, adLockOptimistic
    6. NotRunning.Fields(Live).Value = "Not Running"

    Any idea on what im doin wrong or a better way to do it

    tnx adz
    Last edited by k0r54; Jun 16th, 2004 at 04:14 AM.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Apr 2004
    Posts
    220
    it has to be something simple

  3. #3
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787
    you have to do something like

    VB Code:
    1. recordset.add
    2.  
    3. ("Field") = "not running"
    4.  
    5. recordset.update

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Listbox Database

    What is NotRunning? Is it an ADODB.Recordset?

    Try this.

    VB Code:
    1. Dim NotRunningSelect As String
    2. NotRunningSelect = lstNotRunning.Text
    3.  
    4. If cmdStartStop.Caption = "Stop Campaign" Then  'Why are you doing this?
    5.  
    6. NotRunning.Source "Select * From T_Campaigns WHERE Campaign_Name = '" & NotRunningSelect & "';"
    7. NotRunning.Open , db, adOpenKeyset, adLockOptimistic
    8. NotRunning.Fields(Live).Value = "Not Running"
    9. NotRunning.Update

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Apr 2004
    Posts
    220
    yes it is a adodb connection

    I am now getting an error of

    Runtime Error '3021'
    either bof or eof is tru and the current record hs been deleted requested operation requires a current record

    The record does exist i know it does.

    it is stopping at .feilds....

    i am now using the code
    VB Code:
    1. Dim NotRunningSelect As String
    2. NotRunningSelect = lstNotRunning.Text
    3. If cmdStartStop.Caption = "Stop Campaign" Then
    4. NotRunning.Source = "Select * From T_Campaigns WHERE Campaign_Name = '" & NotRunningSelect & "';"
    5. NotRunning.Open , db, adOpenKeyset, adLockOptimistic
    6. With NotRunning
    7. .Fields("Live").Value = "Not Running"
    8. .Update
    9. End With
    10. End If

    tnx adz

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Do a msgbox of
    objrs.bof
    objrs.eof
    objrs.recordcount

    See what you get.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Apr 2004
    Posts
    220
    sorry but how do i do that :S, i cant remember

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    MsgBox objrs.BOF

    Simple, isn't it?

    Do this after you've opened up the recordset.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Apr 2004
    Posts
    220
    sorry yeah i was putting them all on 1 line lol

    ok bof and eof are true

    and recordcount is 0

  10. #10
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    Use lstNotRunning.List(lstNotRunning.ListIndex) directly, storing to a string is just additional code for a short implementation. Make the list style dropdown list. Make sure there are no special formatting (eg, vbTab, vbCrLf, etc) in the record string, you would never get a match with the list item otherwise.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Apr 2004
    Posts
    220
    firstly it can't be a drop down.

    i have taken out the variable, and now im a bit confused coz do i use lstnotrunning.text or lstnotrunning.list(lstnotrunning.listindex) to tell it what campaign is currently selected.

    But with both i still get the same error,

    also as a Q recordcount is at 0 does this mean there are no records at all, or no records matchin the selected item.

    Thanks Adam

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Apr 2004
    Posts
    220
    ??

  13. #13
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    It means that there is nothing to match. You need to check the values... there will probably be a slight difference between what's on the form, and what's in the db.

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Apr 2004
    Posts
    220
    ok i found the problem

    it is at this point

    VB Code:
    1. WHERE Campaign_Name = ' " & lstNotRunning.List(lstNotRunning.ListIndex) & " ' ;"

    its not finding the selected item i have also tried lstnotrunning.text coz im not sure which on to use.
    Last edited by k0r54; Jun 16th, 2004 at 09:25 AM.

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Apr 2004
    Posts
    220
    ?? i have still had no luck

  16. #16
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    What sort of content does the listbox (and the db table) hold?

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Apr 2004
    Posts
    220
    words

    the table has 5 columns
    Campaign_Name = text
    Start_Date=date but is a text field
    Manager = text
    Assistant = text
    Live = text

    the listbox is pulling the data from from this table so i know the spelling is corrent and everything

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width