Results 1 to 7 of 7
  1. #1
    singhpriyanka is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2018
    Posts
    5

    Passing output Fields from a Query to controsl on Form


    I have a query qrySimCatSolverType as follows-
    SELECT tblSimCategory.SimCategoryID, tblProductSim.Product, tblProductSim.Application, tblProductSim.SolverTypes, tblProductInfo.Productdescription, tblOwner.OwnerFirstName, tblOwner.OwnerLastName, tblOwner.OwnerLoc, tblOwner.DomainID
    FROM tblOwner INNER JOIN (tblProductInfo LEFT JOIN (tblSimCategory RIGHT JOIN tblProductSim ON tblSimCategory.SimCategoryID = tblProductSim.SimCategory) ON tblProductInfo.Productname = tblProductSim.Product) ON tblOwner.OwnerID = tblProductInfo.OwnerID
    WHERE (((tblSimCategory.SimCategoryID) Like "*" & [Forms]![frmAdminShowRecords]![TextSimCatSolver] & "*")) OR (((tblProductSim.SolverTypes) Like "*" & [Forms]![frmAdminShowRecords]![TextSimCatSolver] & "*"));

    The results of could be multiple records in the different fields or just one record. Depends upon the input in the Textbox

    This is basically taking the input from a textbox called "TextSimCatSolver" and displaying results about SimCategoryID, SolverTypes, Product, Application, Productdescription, OwnerFirstName, OwnerLastName, OwnerLoc, DomainID from joined tables as indiacted above. The query runs perfectly fine on its own, but when I try to write it in a string statemnet to open the recordset to access the fileds and assign these to different controls like Combob box , textbox and combobox on my form, I get errors as "Run Time Error 13, Type Mismatch". This what i have so far..

    Dim db As dao.Database
    Dim rs As dao.Recordset
    Dim st As String
    st = "SELECT tblSimCategory.SimCategoryID, tblProductSim.Product, tblProductSim.Application, tblProductSim.SolverTypes, tblProductInfo.Productdescription, tblOwner.OwnerFirstName, tblOwner.OwnerLastName, tblOwner.OwnerLoc, tblOwner.DomainID FROM tblOwner INNER JOIN (tblProductInfo LEFT JOIN (tblSimCategory RIGHT JOIN tblProductSim ON tblSimCategory.SimCategoryID = tblProductSim.SimCategory) ON tblProductInfo.Productname = tblProductSim.Product) ON tblOwner.OwnerID = tblProductInfo.OwnerID WHERE ((((tblSimCategory.SimCategoryID) Like " * " & [Forms]![frmAdminShowRecords]![TextSimCatSolver] & " * ")) OR (((tblProductSim.SolverTypes) Like " * " & [Forms]![frmAdminShowRecords]![TextSimCatSolver] & " * ")))"
    Debug.Print st
    Set rs = CurrentDb.OpenRecordset(st)
    Me.ListSimCategory = ra!SimCategoryID
    Me.ListSolverTypes = ra!SolverTypes
    Me.ComboProduct = ra!Product
    Me.ComboApplication = ra!Application
    Set rs = Nothing

    Set db = Nothing

    Pleas help me!
    Thanks,
    Priyanka

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Why don't you use query as source for form or report then apply filter criteria to form or report?

    If the recordset results in multiple records, then code will take values only from first record.

    Replace the inner quote marks used as text delimiters with apostrophes. Only the one outer pair of quote marks should remain when constructing SQL in VBA.
    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
    singhpriyanka is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2018
    Posts
    5
    Thanks June7. I changed the delimiters to apostrophes. Didn't help. Now I get "Too few Parameters" error.

    st = "SELECT tblSimCategory.SimCategoryID, tblProductSim.Product, tblProductSim.Application, tblProductSim.SolverTypes, tblProductInfo.Productdescription, tblOwner.OwnerFirstName, tblOwner.OwnerLastName, tblOwner.OwnerLoc, tblOwner.DomainID FROM tblOwner INNER JOIN (tblProductInfo LEFT JOIN (tblSimCategory RIGHT JOIN tblProductSim ON tblSimCategory.SimCategoryID = tblProductSim.SimCategory) ON tblProductInfo.Productname = tblProductSim.Product) ON tblOwner.OwnerID = tblProductInfo.OwnerID WHERE ((((tblSimCategory.SimCategoryID) Like ' * ' & [Forms]![frmAdminShowRecords]![TextSimCatSolver] & ' * ')) OR (((tblProductSim.SolverTypes) Like ' * ' & [Forms]![frmAdminShowRecords]![TextSimCatSolver] & ' * ')))"

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Sorry, my mistake. You are concatenating variables (references to controls). Will need to use closing and opening quote marks for each literal string part. Suggest removing spaces from around asterisk.

    ... WHERE ((((tblSimCategory.SimCategoryID) Like '*'" & [Forms]![frmAdminShowRecords]![TextSimCatSolver] & "'*')) OR (((tblProductSim.SolverTypes) Like '*'" & [Forms]![frmAdminShowRecords]![TextSimCatSolver] & "'*')))"
    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
    singhpriyanka is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2018
    Posts
    5
    Quote Originally Posted by June7 View Post
    Sorry, my mistake. You are concatenating variables (references to controls). Will need to use closing and opening quote marks for each literal string part. Suggest removing spaces from around asterisk.

    ... WHERE ((((tblSimCategory.SimCategoryID) Like '*'" & [Forms]![frmAdminShowRecords]![TextSimCatSolver] & "'*')) OR (((tblProductSim.SolverTypes) Like '*'" & [Forms]![frmAdminShowRecords]![TextSimCatSolver] & "'*')))"

    Hello, Sorry If I came out wrong in my explanation of the query. The query is not concatenating as you mentioned but comparing the text value in the textbox to throw results

    For example:
    If user types Dynamic* in the textbox then it should display all the selected fields from the joined tables ad denoted in the query. So the query that works fine is defined as follows, I ahve tested it but when I assign it to a string in VBA, I get errors.

    SELECT tblSimCategory.SimCategoryID, tblProductSim.Product, tblProductSim.Application, tblProductSim.SolverTypes, tblProductInfo.Productdescription, tblOwner.OwnerFirstName, tblOwner.OwnerLastName, tblOwner.OwnerLoc, tblOwner.DomainID
    FROM tblOwner INNER JOIN (tblProductInfo LEFT JOIN (tblSimCategory RIGHT JOIN tblProductSim ON tblSimCategory.SimCategoryID = tblProductSim.SimCategory) ON tblProductInfo.Productname = tblProductSim.Product) ON tblOwner.OwnerID = tblProductInfo.OwnerID
    WHERE (((tblSimCategory.SimCategoryID) Like "*" & [Forms]![frmAdminShowRecords]![TextSimCatSolver] & "*")) OR (((tblProductSim.SolverTypes) Like "*" & [Forms]![frmAdminShowRecords]![TextSimCatSolver] & "*"));

    I tried your solution in the previous post, but I get errors that the opeartor is missing. Please advise

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Save the SQL statement that works as a query (i.e. qrySimCategory) then use the following code to get your recordset:
    Code:
    Dim db as DAO.database
    Dim qdf as DAO.QueryDef
    Dim rst as DAO.Recordset
    Dim prm as Parameter
    
    Set db=CurrentDb
    Set qdf=db.QueryDefs("qrySimCategory")
    
    For Each prm in qdf.parameters
        prm.value=Eval(prm.name)
    Next prm
    
    Set rst=qdf.openrecordset
    'do whatever else with it
    Cheers,
    Vlad

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Your last example does not use apostrophe delimiters as shown in my suggestion.

    And yes, the code is concatenating literal text strings with variables.
    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: 1
    Last Post: 01-09-2015, 12:09 PM
  2. Replies: 2
    Last Post: 07-06-2014, 05:37 PM
  3. Replies: 6
    Last Post: 01-15-2012, 11:07 PM
  4. Passing form fields criteria to a Query
    By yosik20 in forum Queries
    Replies: 1
    Last Post: 05-12-2011, 04:24 AM
  5. Passing data to sequential form fields
    By jeepfamilyva in forum Forms
    Replies: 0
    Last Post: 06-28-2009, 11:04 AM

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