Form/Query Help

  • Thread starter Thread starter Darnell Mirador
  • Start date Start date
D

Darnell Mirador

I have built a form and an instance of that form so that I can lookup
multiple records in a query. my form has an update button that links
to an update query for record updates. I want to run this query to
update the records that I have placed in the fields of the form, but
when I open the instance of the form, the query is still looking at the
original form and its values. How do I update my table with the values
in the 'instance' of my form, rather than the original form? I

want to return the values that I inputted in my form to the table but
the query doesn't recognize the instance of the form. Any help is
appreciated.
 
You could build your sql dynamically, based on the values on your form. Or
you could pass the values to the query as parameters in code, rather than
directly referencing the form controls.

Barry
 
Could you show me an example based on the values stored in the instance
of the form?
 
Let's say your update query had the following sql:

UPDATE tblMyTable Set tblMyTable.[Field1] = Forms!Form1!Text1,
tblMyTable.[Field2] = Forms!Form1!Text2 WHERE tblMyTable.[KeyField] =
Forms!Form1!txtRecId

This query uses the values in two textboxes on a form to update a table
based on an id field. You could copy this sql string into your code module
and make the references to the textboxes dynamic. Something like this:

Dim strSQL As String
strSQL = "UPDATE tblMyTable Set tblMyTable.[Field1] = '" & Forms!Form1!Text1
& "', tblMyTable.[Field2] = '" & Forms!Form1!Text2 & "'WHERE
tblMyTable.[KeyField] = " & Forms!Form1!txtRecId
Docmd.RunSql strSQL

You'd need to play around with the use of quotation marks depending on
whether your table fields are text or numeric.

Barry
 
Back
Top