Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2008
    Posts
    6

    Unanswered: Manipulating SubForms Via Code

    Hi,

    I have a query called DeleteCheckedTS which I want to execute when a button is clicked on a form. How do I access the query object in code? I have tried the Requery option in macro but it's a no go. Is that because it's a delete query?

    To give you an overview of what is going on. I have a subform that displays three values from my table called TS. ID, Current(A Boolean Field), and TS. I have a query that deletes any values in the table that are checked Current. My Subform allows the user to check the value and I have a button that I want to run which will delete the value from the database via the query.

  2. #2
    Join Date
    Feb 2004
    Posts
    214

    ...

    If you want your command button to run your query
    then you would run
    On_Click()
    docmd.openquery "your_query_name"
    End Function

    I am not sure if this is what you are looking for.
    You know, I'm sick of following my dreams, man. I'm just going to ask where they're going and hook up with 'em later

  3. #3
    Join Date
    Nov 2008
    Posts
    6
    I have the following line of code in the button_Click Event.

    DoCmd.OpenQuery DeleteCheckedTS, acViewPreview, acReadOnly

    It gives me a runtime error saying 'The action or method requires a Query Name argument.

    The query I am trying to run is a delete query. That shouldn't make a difference though should it?

  4. #4
    Join Date
    Feb 2004
    Posts
    214

    ...

    Try this
    DoCmd.OpenQuery "DeleteCheckedTS"

    The quotations marks usually have to be around form and query names.
    You know, I'm sick of following my dreams, man. I'm just going to ask where they're going and hook up with 'em later

  5. #5
    Join Date
    Nov 2008
    Posts
    6
    Okay that worked perfectly. Thank you. One other question. When I run the query from the button it first displays the following:

    "You are about to run a delete query that will modify the data in your table. Are you sure you want to run this type of action query?"

    Then:

    "You are about to delete 1 row from the specified table."

    I don't want this message displayed. I am making this very clear throughout the UI what the user will be doing by hitting the button and these alerts are not necessary. I tried this and it didn't work.

    assistant.assistwithalerts=false

    I am used to excel's application.displayalerts=false. It doesn't seem that is the same in Access..

  6. #6
    Join Date
    Nov 2008
    Posts
    8
    DoCmd.SetWarnings False ' Turn off warnings

    DoCmd.SetWarnings True ' Turn warnings on

  7. #7
    Join Date
    Nov 2008
    Posts
    6
    Perfect. It works wonderfully. Thanks again.

Posting Permissions

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