none
[Access 2003 + VBA] Show SELECT query in txtbox RRS feed

  • Question

  • Hi,

    I want the SELECT query to run in vba and show result in a txtbox:

    showRslt = "SELECT product FROM Table1 WHERE Table1.product ='" & Me.txtproductName.Column(1) & "'"
    
    

    How do I run it, please?

    Thanks

    Tuesday, September 27, 2011 6:20 PM

Answers

  • Hi Ronin,

    problem solved with the DLookUp:

    Dim Locate As String
                Locate = DLookup("[product]", "category", "[origin] = '" & Me.combobox2.Column(1) & "'")
    
    


    Thanks

    • Marked as answer by iboumiza Wednesday, October 5, 2011 2:14 PM
    Wednesday, October 5, 2011 2:14 PM

All replies

  • there are many ways on accomplishing this... but here is a sample:

     

        Dim db As DAO.Database, rst As DAO.Recordset
        Set db = CurrentDb()
        Set rst = db.OpenRecordset("SELECT product  FROM Table1 WHERE Table1.product ='" & Me.txtproductName.Column(1) & "'")
        Text0.Value = rst.Fields(0)

     


    • Edited by RoninB Tuesday, September 27, 2011 6:50 PM
    Tuesday, September 27, 2011 6:49 PM
  • hi, I'm sorry but it do not return anything in the text box...
    Tuesday, September 27, 2011 9:26 PM
  • hi, I'm sorry but it do not return anything in the text box...


    Did you reference DAO?

    Do you have any code at all you can post so that the forum may analyze?

    what is showRslt? a variable, textbox, etc..?

    are you running the codeblock i've posted in an event?

    your statement above does not help. I'd ran the code and it works using the version (MS Access 2003) you'd mentioned.

    Please ask the right question.

    Wednesday, September 28, 2011 1:03 AM
  • the error message that I receive is:

    Run-time error 91:

    Object variable or With block variable not set

     

    Dim showRslt As String

    I'm using your code block in OnClick event and I'm using Access 2003 also.

     

    The result that showRslt get is then transferred to:

    .CC = showRslt (it posts the name in an Outlook session)

    Regards


    • Edited by iboumiza Wednesday, September 28, 2011 1:35 AM refine
    Wednesday, September 28, 2011 1:33 AM
  • do you have a variable that the value is not set?

    if so... the variable must use the 'SET' statement

    did you try stepping into the code line to determine what variable is not set? look in the local window as well.

    if you step through the codeline that i posted, does it error out at any of those lines?

    If you are unsure of how to set breakpoints... please advice.

    Wednesday, September 28, 2011 4:19 AM
  • Hi Ronin,

    problem solved with the DLookUp:

    Dim Locate As String
                Locate = DLookup("[product]", "category", "[origin] = '" & Me.combobox2.Column(1) & "'")
    
    


    Thanks

    • Marked as answer by iboumiza Wednesday, October 5, 2011 2:14 PM
    Wednesday, October 5, 2011 2:14 PM