Inserting a Date into existing query in Form

D

Dan N

I have a form that has a hard coded query that returns results and would like
to have a textbox that takes a date in and uses that date instead of the hard
coded date that is there now. I have the textbox on the form with the button
that runs the query, how would i go about using the textbox info to insert
that info into the query?
 
R

Rick B

Replace your query hard-coded criteria with...


=Forms![MyFormName]![MyFieldName]
 
O

Ofer

If I understood you then you want to insert a date that you input in a text
box into a table using a query.
if so then on the click of the button you write

declare MySql as string
if not isnull(Me.textBxo ) then
MySql= "UPDATE MyTable2 SET MyTable2.StartDate = #" & Me.textBxo & "#
Where ...."
else
msgbox "NoDate"
endif

docmd.runsql MySql
 
D

Dan N

Rick,
Thanks for your help, it works to a point so my next question is why is it
doing it this way now. When i entered {form1}![Text2} in the query area and
when i goto the form and enter date and click on the button to run query i
get an error stating "invalid sequel statement: expected "Delete" "Insert"
"Procedure" "select" or "Update".
When i click on the query in the query area a window opens to enter
parameter value and i enter the date there and the query works fine.

Rick B said:
Replace your query hard-coded criteria with...


=Forms![MyFormName]![MyFieldName]


--
Rick B



Dan N said:
I have a form that has a hard coded query that returns results and would like
to have a textbox that takes a date in and uses that date instead of the hard
coded date that is there now. I have the textbox on the form with the button
that runs the query, how would i go about using the textbox info to insert
that info into the query?
 
Top