Results 1 to 4 of 4
  1. #1
    Phred is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2009
    Posts
    246

    How do I pass the results of a select query to a VBA module and then to variables?

    Access 2007 and SQL Server 2008 R2.

    I have a query that runs fine. I would like to pass the results to VBA variables. Then I will write an update query in VB and update the Property table and then run a requery to update the screen.

    SELECT dbo_TownshipLookup.TownshipName, dbo_TownshipLookup.TownshipNO,dbo_CountyLookup.Cou ntyName, dbo_TriCycleLookup.CycleName, dbo_VolumeLookup.Volume
    FROM ((dbo_TownshipLookup INNER JOIN dbo_TriCycleLookup ONdbo_TownshipLookup.TricountyID = dbo_TriCycleLookup.TricountyID) INNER JOINdbo_CountyLookup ON dbo_TriCycleLookup.CountyID = dbo_CountyLookup.CountyID)INNER JOIN dbo_VolumeLookup ON dbo_TownshipLookup.TownshipName =dbo_VolumeLookup.Township;

    The query runs fine and returns the proper results. What I don't know is how to pass the results of the query to the VBA module. I am ok with the syntax and variables involved, I just don't know how to create the methodology to capture the query results and place them into appropriate variables. I think I create a record set for the results but I'm not really sure.

    Thanks


    Phred

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Yes, open a recordset object.

    Or build an UPDATE query object.

    What do you need to update?
    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
    Phred is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2009
    Posts
    246
    I have a Property screen with a combo box. The combo box is based on the query above and returns the Township Name as well as several other fields. See Pic 1.

    Click image for larger version. 

Name:	PropertyScreen.JPG 
Views:	5 
Size:	46.4 KB 
ID:	16773


    When the person selects the Township it places the township in the combo box. See Pic 2.

    Click image for larger version. 

Name:	Township.JPG 
Views:	5 
Size:	81.8 KB 
ID:	16774

    But the query that is behind the combo box also contains data that could be written in the additional fields
    Township No:
    County:
    Triennial Cycle:
    Volume:

    I need to do one of two things:

    Find a way to have the combo box write the additional fields of information from the Query behind the combo box to the fields below the combo box. I've never seen a combo box write to additional fields like that. I'm not sure it's even possible.

    Or

    Use VB to pull the data from the combo box query into VB and have it update the table behind the Property screen and then requery the Property screen to update the data.

    I have to get all the data to assist the end user select the correct township. I might as well use it to populate the additional fields below automatically.

    Hope that makes sense.

    Thanks,

    Phred

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    The other textboxes can have expression in ControlSource that references columns of combobox. Column index begins with 0. So if County is in column 2 it is index 1.

    =[cbxTownship].[Column](1)

    This will display the related info but will not save to table. However, should probably not save this related data anyway. That would be duplication of data.
    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.

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

Similar Threads

  1. Replies: 5
    Last Post: 05-14-2014, 01:17 PM
  2. Pass variables from Access to Excel
    By WhatTheFrick in forum Programming
    Replies: 1
    Last Post: 04-28-2013, 12:17 PM
  3. Trouble defining variables - Access Module
    By David92595 in forum Modules
    Replies: 1
    Last Post: 11-29-2012, 07:09 PM
  4. Replies: 2
    Last Post: 06-25-2012, 09:24 AM
  5. How to pass what was clicked to module?
    By nichojo in forum Modules
    Replies: 11
    Last Post: 07-22-2010, 08:27 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