Results 1 to 5 of 5
  1. #1
    dolovenature is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2012
    Posts
    14

    Running SELECT query in MSACCESS

    Hi,



    I have the following problem. I am designing a form based on a table in ms access. I want to run a select query from a command button.

    My problem is....

    1) What are the way to run a SELECT query from access as a simple SQL query is not run in access directly.
    2) How to create table alias?

    Regards
    Saikat

  2. #2
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    What is is you want to do with the Select query? You have the form based on a table, but the what is the button supposed to do?

    John

  3. #3
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I am afraid I am not quite clear exactly what your question is.

    If you have created a Query and would like to run it from a Command Button, then when adding the Command Button, the Wizard should prompt you for what you what do.
    If you select "Miscellaneous", there is a "Run Query" option. Then just select the name of the Query you want to run, and that is what your Command Button will do.

    Is that what you are asking?

  4. #4
    dolovenature is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2012
    Posts
    14
    Actually I have a command button, and when it is clicked it should select top students based on their marks.

    My code is

    SELECT StudentID,STName, STMarks, City
    FROM Table1
    WHERE (City = "Mumbai")
    ORDER BY STMarks;

    After writing it is showing me the message error : expected case.
    My friend told me that running a sql statement in access requires something more trics.

    Please highlight.

    Regards
    Saikat


  5. #5
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I don't think you can run Select queries directly from VBA.
    If you want to open/view a Select Query using VBA, assign the SQL code to a pre-defined saved Query, then open that Query, i.e.

    Code:
    Dim mySQL as String
    
    mySQL="SELECT StudentID,STName, STMarks, City " & _
               "FROM Table1  " & _
               "WHERE City = " & Chr(34) & "Mumbai" & Chr(34) " & _
               "ORDER BY STMarks;"
    
    CurrentDb.QueryDefs("MyQueryName").SQL=mySQL
    DoCmd.OpenQuery "MyQueryName"

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Learn MSAccess by playing MSAccess Jeopardy
    By pkstormy in forum Sample Databases
    Replies: 4
    Last Post: 11-17-2016, 07:27 AM
  2. Running a Select statement in VBA
    By geraldk in forum Forms
    Replies: 12
    Last Post: 05-04-2012, 01:23 PM
  3. Replies: 1
    Last Post: 03-15-2012, 10:45 AM
  4. running select query in form delete event
    By suki360 in forum Programming
    Replies: 0
    Last Post: 03-11-2011, 10:11 AM
  5. Select query for running totals
    By asawadude in forum Queries
    Replies: 2
    Last Post: 10-07-2010, 03:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums