Passing parameters to form and query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jahangir
    New Member
    • Oct 2006
    • 22

    Passing parameters to form and query

    Dear Fellows,

    I m in in Access VB, and working on a small project.
    Problem is that

    In main form (called search )I have made a textbox name text34, and a search button, which responsiblity is to open a form.
    I have made a query that show results which 'like Form.search.tex t34.text'.
    when i execut this query by double clicking its ask me to enter value of Form.search.tex t34.text and show correct results.
    On the same i made an other form base on that query. which also works fine when double click on that form on same principles as for query.

    Now problem is that when I enter data through search form and press search it shows all the records and does not consider criteria entered.

    If this cannot be achieved then please tell me any other way by which i can get the desired results.
    i.e. pass parameter to query and then to form.
    in my project execution sequence is
    search button->form->query->selct date from text34

    Plz help me. Thx
  • pks00
    Recognized Expert Contributor
    • Oct 2006
    • 280

    #2
    Instead of

    like Form.search.tex t34.text'

    try this syntax

    like Forms!Search!te xt34

    if it dont have asterix in that textbox. try this

    like "*" & Forms!Search!te xt34 & "*"


    I recommend u rename your textbox from text34 to something more meaningful

    Comment

    • MMcCarthy
      Recognized Expert MVP
      • Aug 2006
      • 14387

      #3
      [QUOTE=Jahangir]

      The standard way to open a form with criteria

      Dim stDocName As String
      Dim stLinkCriteria As String

      stDocName = "Name of form to be opened"
      stLinkCriteria = "[FieldOnForm]=" & Me.[textboxName]

      DoCmd.OpenForm stDocName, , , stLinkCriteria

      Comment

      • pks00
        Recognized Expert Contributor
        • Oct 2006
        • 280

        #4
        Just to expand on mmccarthy's post (not taking credit though :-D)

        For strings u need single quotes

        stLinkCriteria = "[FieldOnForm]='" & Me.[textboxName] & "'"

        for strings with single quotes in then use chr$(34)

        stLinkCriteria = "[FieldOnForm]=" & chr$(34) & Me.[textboxName] & chr$(34)

        and for dates the use #'

        stLinkCriteria = "[FieldOnForm]=#" & Me.[textboxName] & "#"

        Comment

        Working...