Results 1 to 8 of 8
  1. #1
    frksdf is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2011
    Posts
    12

    [SOLVED] Formula cannot retrieve value from Combobox

    Hi Experts;

    I have an issue about VBA functions in Access. I am using a code to define function "Concatenate".
    I am using this code with a textbox. If you use Concatenate function in textbox like this,
    Code:
     =Concatenate("Select Supp_Series FROM Supplier")
    the Code retrieves the Supp_Series from Supplier table and put them in textbox seperated with (-).

    But İf you use a SQL statement like below, it gives error.
    Code:
     
    =Concatenate("Select Supp_Series FROM Supplier WHERE [Forms]![Form1]!Combo10")
    What is the problem ? Why we cannot link a value in Form ? How we should amend the code.

    And this is the Concatanate function code that lives in a module.
    Code:
     
    Function Concatenate(pstrSQL As String, Optional pstrDelim As String = "- ") As String
    Dim rs As New ADODB.Recordset
    rs.Open pstrSQL, CurrentProject.Connection, adOpenKeyset, adLockReadOnly
    Dim strConcat As String 'build return string
    With rs
    If Not .EOF Then
    .MoveFirst
    Do While Not .EOF
    strConcat = strConcat & _
    .Fields(0) & pstrDelim
    .MoveNext
    Loop
    End If
    .Close
    End With
    Set rs = Nothing
    If Len(strConcat) > 0 Then
    strConcat = Left(strConcat, _
    Len(strConcat) - Len(pstrDelim))
    End If
    Concatenate = strConcat
    End Function

    Last edited by frksdf; 01-31-2012 at 10:56 AM.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Your WHERE clause is not complete.

  3. #3
    frksdf is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2011
    Posts
    12
    Hi Rural Guy,
    I accidently write wrong sql statement on th forum.

    I use ;
    Code:
     
    =Concatenate("Select Supp_Series FROM Supplier WHERE Supp_Company = [Forms]![Form1]!Combo10")
    and it still gives error.

    The error message is " Run-time Error.'-2147217904 (80040e10)' No value given for one or more required parameters."

    Also, the line that gives error in the VBA code, is 4. line above.

    Thank you very much Rural Guy.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    If your Supp_Company is a TEXT value then you need to surround the value with quotes.

  5. #5
    frksdf is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2011
    Posts
    12
    Hi Rural Guy,
    I am very happy for your help and interest.

    But it still doesn't work. Perhaps I can't be success and I am making mistake somewhere else.

    I am sending you very simple example atttached. Could you please look it ?

    You will see my question and problem on the form.

    Thank you very much.

  6. #6
    joelmeaders is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jan 2012
    Posts
    33

    Fixed

    I got it. The bottom text box should be:

    =Concatenate("Select Cars.Brand FROM Cars Where Cars.Age = " & [Forms]![Form1]!Combo5)

    This is because you have a number datatype and the double quotes convert it to a string which gives a mismatch

  7. #7
    frksdf is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2011
    Posts
    12
    Quote Originally Posted by joelmeaders View Post
    I got it. The bottom text box should be:

    =Concatenate("Select Cars.Brand FROM Cars Where Cars.Age = " & [Forms]![Form1]!Combo5)

    This is because you have a number datatype and the double quotes convert it to a string which gives a mismatch

    You are great joelmeaders; thank you.

    Also thank to the RuralGuy

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Excellent! Thanks for posting back with your success and solution.

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

Similar Threads

  1. Replies: 1
    Last Post: 09-06-2011, 01:47 PM
  2. Replies: 29
    Last Post: 08-16-2011, 05:52 PM
  3. Replies: 0
    Last Post: 08-24-2010, 06:38 PM
  4. Search and Retrieve
    By sadath in forum Access
    Replies: 3
    Last Post: 07-02-2010, 04:54 AM
  5. Replies: 0
    Last Post: 12-16-2009, 01:14 PM

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