Results 1 to 2 of 2
  1. #1
    Tyork is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Oct 2010
    Posts
    35

    DAO Connection

    I am trying to populate a field on a form with a SQL query that is fed variables from some vba code.



    I would like the information to populate on an event action but can't quite figure out how to do it. The vba code basically establishes an array of months and years for use in my select statements. the vba procedure name is DetectMonth. I have the following code.

    Code:
     
    Call DetectMonth
     
    strSQL = "SELECT Project FROM [Client Relationships] WHERE Client = [Forms].[Strategy Binder].Client AND M = " _
    & "'" & CurrentMonth0 & "'" & " AND Y = " & CurrentYear0 & ";"
    What I am lacking is:

    1. The DAO connection information to the table which is named [Client Relationships]
    2. A link between the form field and the query result

    The query result will be 1 record consisting of one word

    Any help would be appreciated. My main struggle is the DAO connection information. I haven't used access much for programming but would like to take a lot of the work I've done in excel and convert it to access.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Here's my DAO recordset template:

    Code:
      Dim strSQL  As String
      Dim db      As DAO.Database
      Dim rs      As DAO.Recordset
    
      Set db = CurrentDb()
      
      strSQL = "SELECT ..."
      Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
    
      set rs = nothing
      set db = nothing
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. ODBC connection
    By avicenna in forum Import/Export Data
    Replies: 2
    Last Post: 08-02-2010, 02:33 AM
  2. Close DAP Connection
    By gfultz in forum Access
    Replies: 0
    Last Post: 10-16-2009, 10:11 AM
  3. connection performance
    By DanM in forum Programming
    Replies: 0
    Last Post: 08-24-2008, 08:25 AM
  4. Connection to same DB
    By emilylu3 in forum Access
    Replies: 1
    Last Post: 12-30-2005, 09:59 AM
  5. connection to db
    By emilylu3 in forum Access
    Replies: 2
    Last Post: 12-29-2005, 01:06 PM

Tags for this Thread

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