Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!
  1.   Become a Supporter    ::   Make a Contribution   
    Target (Recurring Monthly): $200 :: Achieved: $98

how to delete record from cbo

Discussion in 'Information Technology' started by James, Jul 28, 2006.

Tags:
  1. James

    James
    Expand Collapse
    Guest

    how do i get it to delete userID?


    Dim UserID As String

    UserID = cboUserID.Value

    DoCmd.RunCommand (acCmdDeleteRecord)

    Thanks!
     
  2. Loading...


  3. John Vinson

    John Vinson
    Expand Collapse
    Guest

    On 13 Jun 2006 07:52:39 -0700, "James" <jamesburkett@gmail.com> wrote:

    >how do i get it to delete userID?
    >
    >
    >Dim UserID As String
    >
    >UserID = cboUserID.Value
    >
    >DoCmd.RunCommand (acCmdDeleteRecord)
    >
    >Thanks!


    What are you trying to delete? A value from the Combo's RowSource? A
    record in the table upon which the form is based? or what?

    John W. Vinson[MVP]
     
  4. James

    James
    Expand Collapse
    Guest

    the cbo is pulling from a table, I want the delete button to reference
    the cbo and delete that record from the table... does that make since?

    John Vinson wrote:
    > On 13 Jun 2006 07:52:39 -0700, "James" <jamesburkett@gmail.com> wrote:
    >
    > >how do i get it to delete userID?
    > >
    > >
    > >Dim UserID As String
    > >
    > >UserID = cboUserID.Value
    > >
    > >DoCmd.RunCommand (acCmdDeleteRecord)
    > >
    > >Thanks!

    >
    > What are you trying to delete? A value from the Combo's RowSource? A
    > record in the table upon which the form is based? or what?
    >
    > John W. Vinson[MVP]
     
  5. John Vinson

    John Vinson
    Expand Collapse
    Guest

    On 13 Jun 2006 10:52:21 -0700, "James" <jamesburkett@gmail.com> wrote:

    >the cbo is pulling from a table, I want the delete button to reference
    >the cbo and delete that record from the table... does that make since?
    >


    I'd suggest using a Delete Query:

    Private Sub cmdDeleteRecord_Click()
    Dim strSQL As String
    Dim db As DAO.Database
    Dim qd As DAO.Querydef
    On Error GoTo Proc_Error
    Set db = CurrentDb
    ' define the SQL of the query to delete the record
    strSQL = "DELETE * FROM table WHERE [UserID] = " & Me!cboUserID
    ' create an unnamed new query definition (the "" is the name)
    Set qd = db.CreateQuerydef("", strSQL)
    qd.Execute dbFailOnError
    Proc_Exit:
    Exit Sub
    Proc_Error:
    Msgbox "Error " & Err.Num & " in cmdDeleteRecord_Click:" _
    & vbCrLf & Err.Description
    Resume Proc_Exit
    End Sub

    John W. Vinson[MVP]
     
  6. James

    James
    Expand Collapse
    Guest

    John, first thanks for helping me out... yesterday when I reposted,
    your post hadn't shown up yet and I was just trying to get it figured
    out... anyways, when I type in what both of you had suggested, I get an
    error " Too few parameters" referring to this line:

    qd.Execute dbFailOnError


    I copied your format verbatim, changing the table to my table name and
    changing the function name in the error msg to my function.... here's
    the rest of my code. Thanks again for your help... what you wrote makes
    since even though I have no experience with sql via access/vb...
    thanks....

    Private Sub cmdDelete_Click()
    Dim strSQL As String
    Dim db As DAO.Database
    Dim qd As DAO.QueryDef


    On Error GoTo Proc_Error
    Set db = CurrentDb

    'define the SQL of the query to delete the record
    strSQL = "DELETE * FROM UserIDandPassword WHERE [USERID] =" &
    Me!cboUserID

    'create an unnamed new query definition (the "" is the name)
    Set qd = db.CreateQueryDef("", strSQL)
    qd.Execute dbFailOnError

    Proc_Exit:
    Exit Sub

    Proc_Error:
    MsgBox "Error " & Err.Number & " in cmdDelete_Click:" _
    & vbCrLf & Err.Description
    Resume Proc_Exit
     
  7. James

    James
    Expand Collapse
    Guest

    ok... i figured it out... but thanks a lot for all your help... i just
    needed to put my comment box in quotes then it worked... so it looks
    like this....


    strSQL = "DELETE * FROM UserIDandPassword WHERE [USERID] = '" &
    Me!cboUserID & "'"

    thanks again for your time!

    -James

    James wrote:
    > John, first thanks for helping me out... yesterday when I reposted,
    > your post hadn't shown up yet and I was just trying to get it figured
    > out... anyways, when I type in what both of you had suggested, I get an
    > error " Too few parameters" referring to this line:
    >
    > qd.Execute dbFailOnError
    >
    >
    > I copied your format verbatim, changing the table to my table name and
    > changing the function name in the error msg to my function.... here's
    > the rest of my code. Thanks again for your help... what you wrote makes
    > since even though I have no experience with sql via access/vb...
    > thanks....
    >
    > Private Sub cmdDelete_Click()
    > Dim strSQL As String
    > Dim db As DAO.Database
    > Dim qd As DAO.QueryDef
    >
    >
    > On Error GoTo Proc_Error
    > Set db = CurrentDb
    >
    > 'define the SQL of the query to delete the record
    > strSQL = "DELETE * FROM UserIDandPassword WHERE [USERID] =" &
    > Me!cboUserID
    >
    > 'create an unnamed new query definition (the "" is the name)
    > Set qd = db.CreateQueryDef("", strSQL)
    > qd.Execute dbFailOnError
    >
    > Proc_Exit:
    > Exit Sub
    >
    > Proc_Error:
    > MsgBox "Error " & Err.Number & " in cmdDelete_Click:" _
    > & vbCrLf & Err.Description
    > Resume Proc_Exit
     
Since you're here... we have a small favor to ask...

More people are visiting & reading SPN than ever but far fewer are paying to sustain it. Advertising revenues across the online media have fallen fast. So you can see why we need to ask for your help. Donating to SPN's is vote for free speech, for diversity of opinions, for the right of the people to stand up to religious bigotry. Without any affiliation to any organization, this constant struggle takes a lot of hard work to sustain as we entirely depend on the contributions of our esteemed writers/readers. We do it because we believe our perspective matters – because it might well be your perspective, too... Fund our efforts and together we can keep the world informed about the real Sikh Sikhi Sikhism. If everyone who writes or reads our content, who likes it, helps us to pay for it, our future would be much more secure. Every Contribution Matters, Contribute Generously!

    Become a Supporter      ::     Make a Contribution     



Share This Page