Results 1 to 4 of 4
  1. #1
    Playerpawn is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    11

    Exclamation Use query result to open form.

    Hi,

    I have a form with a text edit field (input_text) and button control (go_button).

    When the user clicks the button (go_button), I want it to pass the text in the editable field (input_text) into a saved query (qry_myquery). This will return either NULL or a number.

    If null is returned, I want it to say it's a bad input and to clear the text control (input_text).



    If a number is returned, I want it to close the current form and open a differnt form based on the result (ie, 1 = open form1, 2= open form2). Additionally, I would like to pass the editable field's data (input_text) into the newly opened form and have it auto populated into it's editable control (new control, new_forms_input_text).

    Can someone help with this, please?

  2. #2
    pkstormy's Avatar
    pkstormy is offline Access/SQL Server Expert
    Windows XP Access 2003
    Join Date
    Mar 2010
    Location
    Madison
    Posts
    682
    The best way I can think of is to have a function which does this. You can use a query expression such as: =iif(Forms!MyFormName!Input_Text = "X",null)

    I'd write a function though. This you can then call this function in the query and refine how you want the number returned.

    For Example:
    Function retCalcNumber(vSomeVariable as variant) as variant
    if isnull(vSomeVariable) then
    retCalcNumber = null
    exit function
    end if
    if vSomeVariable = <some equation here> then retCalcNumber = <some calculation here>.
    end function

  3. #3
    Playerpawn is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    11
    How do I get the result of a query into a function's variable?

    I have qry_which_one which will ultimately return 1, 2 or 3 when executed. I want that result into a variable within a function, so the function can take action based on the query's result.

    ty

  4. #4
    pkstormy's Avatar
    pkstormy is offline Access/SQL Server Expert
    Windows XP Access 2003
    Join Date
    Mar 2010
    Location
    Madison
    Posts
    682
    Try using the dlookup command. You could do this within the function also. The dlookup command will look up a value in a query or return the single value if there are no others (ie. no paramaters are supplied). - ex: somevariable = dlookup("[FieldNameinQuery]","QueryName")

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

Similar Threads

  1. open form if no records in query
    By MiaAccess in forum Forms
    Replies: 1
    Last Post: 03-05-2011, 12:11 PM
  2. Replies: 29
    Last Post: 02-13-2011, 01:21 AM
  3. HELP! Display a query result into form
    By leanne in forum Forms
    Replies: 15
    Last Post: 06-23-2010, 09:18 PM
  4. Replies: 1
    Last Post: 05-18-2010, 12:05 PM
  5. Open a form using a query that references a combo
    By accessbobp646 in forum Access
    Replies: 1
    Last Post: 02-22-2009, 09:50 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