Results 1 to 7 of 7
  1. #1
    lawdy is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    172

    Code wanted to run a SQL fron a button


    I am obviously new to Access. I need to run a 'select' sql from a button. Everything I find says it wil run any sql except a select one. Any help is thanlfull.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    A button can 'open' Access SELECT query object. Why do you need to open query?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    lawdy is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    172

    Here is my code

    Below is my code, which don't work. To answer your queston, it appears (in Access) that the best way to get information from a table is to query it.

    Private Sub btnQuery_Click()
    ' Locate records
    Dim db As Database
    Dim rst As Recordset
    Set db = DBEngine(0)(0)
    Set rst = db.OpenRecordset("tblBankRegistar", dbOpenSnapshot)

    rst.OpenRecordset "SELECT tblBankRegistar.fTxtAccount, tblBankRegistar.fTxtCheckNo FROM tblBankRegistar"

    End Sub

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    That opens a recordset, not an Access query object.

    A recordset can be manipulated in code. Values in fields of recordset can be used in code but there is nothing you can see.

    Again, why do you need to open a SELECT query? What do you want to do with the data?

    Build form or report with query as RecordSource.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    lawdy is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    172
    I have to match criteria in 2 different fields to get the next unused check number. There is more than one checking account, so I can't just use the previous high check number or date. I need to match the account number and the check number. What I know about 'findFirst' indicates that only one field can be matched. I appears that in 'seek', the fields must be in the primary index.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    FindFirst can have multiple criteria. It's just like the WHERE clause of an SQL statement. Any number of fields can be used with AND or OR operator.

    "AccountNumber=" & value & " AND DateEnter=#" & value & "# AND Category='" & value & "'"

    Alternative to recordset code is domain aggregate function.

    x = DMax("CheckNumber", "tablename", "AccountNumber=" value)
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    lawdy is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    172
    That is super. I have 4 books on access and the internet and that is the first I have heard on that. Thank you very much.

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

Similar Threads

  1. Help wanted in SW Wisconsin
    By ldodge in forum Access
    Replies: 0
    Last Post: 06-30-2011, 06:21 AM
  2. a bar on the side not wanted
    By techexpressinc in forum Forms
    Replies: 4
    Last Post: 06-28-2011, 07:49 AM
  3. Crosstab Query Help Wanted
    By goodguy in forum Queries
    Replies: 19
    Last Post: 12-30-2010, 10:29 AM
  4. Programmer Wanted
    By Hoota Caroota in forum Access
    Replies: 2
    Last Post: 11-15-2010, 08:56 PM
  5. 90 days in the pass - Date help wanted
    By techexpressinc in forum Queries
    Replies: 1
    Last Post: 01-26-2009, 07:13 AM

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