Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using VBA to update table 1

Status
Not open for further replies.

AKMonkeyboy

IS-IT--Management
Feb 4, 2002
141
US
I have been using queries that run on the "AfterUpdate" event, but have a form that is opening as a subform in several other forms and to avoid having to create multiple versions of forms/queries I'd like to be able to update tables using fields found in my forms (not sure I'm saying that so it makes sense...). See if this does any better...

How could I take the following query and execute it from a form WITHOUT the references to the particular form?

UPDATE tblPrescriptions SET tblPrescriptions.Dose = [Forms]![FrmPatientMeds]![Dose], tblPrescriptions.Frequency = [Forms]![FrmPatientMeds]![Frequency], tblPrescriptions.Description = [Forms]![FrmPatientMeds]![Note], tblPrescriptions.Route = [Forms]![FrmPatientMeds]![Route]
WHERE (((tblPrescriptions.DrugName)=[Forms]![FrmPatientMeds]![Prescription]));

I have some code that allows updating using the rs.update, but I'm not sure how to apply that when I only want certain rows / fields updated.

Totally confused,

Monkey




Give a man a fish, and you feed him for a day.
Teach a man to fish, and you feed
him for life.
Send a man to Tek-Tips and the poor sap can find out how to fish on his own, and learn more by doing it.
 
If the event procedure is in FrmPatientMeds, you may consider something like this:
Code:
Dim strSQL As string
strSQL = "UPDATE tblPrescriptions" _
  & " SET Dose='" & Me![Dose] & "',Frequency='" & Me![Frequency] & "'" _
  & ",Description='" & Me![Note] & "',Route='" & Me![Route] & "'" _
  & " WHERE DrugName='" & Me![Prescription] & "'"
DoCmd.RunSQL strSQL

For any field defined as numeric get rid of the corresponding single quotes.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
GENIUS!

Thanks PHV - Have a star!



Give a man a fish, and you feed him for a day.
Teach a man to fish, and you feed
him for life.
Send a man to Tek-Tips and the poor sap can find out how to fish on his own, and learn more by doing it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top