Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2003
    Location
    Columbia, MO
    Posts
    57

    Unanswered: Visual Basic Running queries

    I need some VB help. I have a command button that I want to run 2 append queries and then a delete query, but I can't quite figure out how to get them to run. I am in the cattle business, so that is why I have the heifer and cow lingo! I have the following in the OnClick part of the VB screen:

    Private Sub MakeCows_Click()
    Dim db As DAO.Database
    Dim qdf As DAO.QueryDef
    Dim tdf As DAO.TableDef
    Dim rst As DAO.Recordset
    Dim varitm As Variant
    Dim ctl As Control
    Set db = CurrentDb()
    Set ctl = Me.SelHfrs
    DoCmd.SetWarnings (False)
    Set qdf = db.QueryDefs("qryHeiferToCowAppend")
    qdf.Execute
    Set qdf = db.QueryDefs("qryHeiferToCowLocAppend")
    qdf.Execute
    Set qdf = db.QueryDefs("qryDeltblHfrCow")
    qdf.Execute
    DoCmd.SetWarnings (True)
    Set tdf = db.TableDefs("tblHfrCow")
    Set rst = tdf.OpenRecordset
    End Sub


    When I run it, I get:

    Run-time error '3061':
    Too few parameters. Expected 2.

    When I go to Debug it highlights the first qdf.Execute in the code. I know relatively nothing about VB, but I am slowly seeing the need to.
    Any help would be appreciated.

    Thanks,

    David

  2. #2
    Join Date
    May 2003
    Posts
    19
    This reply may be too basic for you, David, and I apologise in advance if it is. But the code you need to run your queries is provided by macros. Get macros to run each of these queries and then convert the macros to VBA code. Keep the code, of course, because with a little adapting, you can use it/them to run other access tasks.

  3. #3
    Join Date
    Jan 2003
    Location
    Rockville, MD
    Posts
    179

    Re: Visual Basic Running queries

    Try it this way, David.
    Code:
    Private Sub MakeCows_Click()
       DoCmd.SetWarnings (False)
       DoCmd.OpenQuery "qryHeiferToCowAppend"
       DoCmd.OpenQuery "qryHeiferToCowLocAppend"
       DoCmd.OpenQuery "qryDeltblHfrCow"
       DoCmd.SetWarnings (True)
       DoCmd.OpenTable "tblHfrCow"
    End Sub

  4. #4
    Join Date
    Jan 2003
    Location
    Columbia, MO
    Posts
    57
    Thanks! That worked like a dream. I have got to work on learning more. I appreciate all your help.

  5. #5
    Join Date
    Jan 2003
    Location
    Rockville, MD
    Posts
    179

    Thumbs up

    Looks like you're well on your way!

Posting Permissions

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