1

REPHRASING QUESTION:

i apologize for being unclear. i have a textbox and a button a form. when the button is clicked it runs this saved access query:

select * from sqlservertable where field=form!textbox.value

i have an access front end and sql server back end.

this query is not working. it doesnt like me passing this parameter form!textbox.text. is there an alternate way to pass the value of the textbox?

7
  • You want to pass it as an access variable or as a SQL @variable? Commented Oct 20, 2010 at 20:45
  • @JNK, i just want to pass the text from the textbox into the sql statement Commented Oct 20, 2010 at 20:46
  • Could you rephrase your question? I don't understand your question. Commented Oct 20, 2010 at 20:46
  • @everyone: woudl this be the right solution? blueclaw-db.com/accessquerysql/parameter_query.htm Commented Oct 20, 2010 at 21:07
  • When you say "runs this saved query" what do you mean? Does the button call DoCmd.OpenQuery? If not, it's unclear what you mean, since SELECT queries don't do anything other than display data (i.e., they perform no actions). Commented Oct 21, 2010 at 4:24

2 Answers 2

2

The .Text property of an Access control is available only what that control has the focus.

Secondly, in Access, you refer to forms as members of the Forms collection, i.e., the collection of open forms.

So, you use:

  Forms!FormName!ControlName

Without specifying the Forms collection as the container object for the form, the Access expression service won't know where to find the control.

And as .Value is the default property of controls, you don't need to specify it, though if you want to be really picky and explicit and type more characters for no actual benefit in this context, you could use:

  Forms!FormName!ControlName.Value

But that won't behave any differently at all in this context (the only situation where it will is if you're trying to force evaluation of the control before passing it as a parameter of a subrountine, in which case without .Value you may end up passing a control reference instead of the value, which could be bad or it could be fine).

Sign up to request clarification or add additional context in comments.

2 Comments

thanks so much for your help. i worded my question incorrectly by saying that i was passing the TEXT property, i was actually indeed passing the VALUE property and it wasnt working
But you weren't using the Forms collection.
1

Have you tried setting the RecordSource property on the form (from code) with:

Form.RecordSource = "SELECT ... FROM ... WHERE [Occurrence Date] BETWEEN " & Text1 & " AND " & Text2

4 Comments

thanks for your answer. ive rephrased my question. please let me know if i can clarify anythign else
Try Me!Textbox instead of form!textbox.text
Also, if you're doing this by code I think you need to do a Me.Requery
at which point woudl i do the requery? it is working perfectly fine when the data is in access, not sql-server

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.