PDA

View Full Version : Update Query



TedMosby
01-13-2009, 03:17 AM
I have an update query that I run to submit the records from my form into my SQL Server table.

This below is my code


sQRY = "UPDATE jez_SWM_Visits " & _
"SET [NHSNo] = '" & Me.txtNHSNo & "', [Surname] = '" & Me.txtSurname & "', [Forename] = '" & Me.txtForename & "', [Gender] = '" & Me.cboGender & "', [Address1] = '" & _
Me.txtAddress1 & "', [Address2] = '" & Me.txtAddress2 & "', [Address3] = '" & Me.txtAddress3 & "', [Postcode] = '" & Me.txtPostcode & "', [Telephone] = '" & _
Me.txtTelephone & "', [DateOfBirth] = '" & Me.txtDOB & "', [ReferralReasonDescription] = '" & Me.cboReferralRsn & "', [SourceDescription] = '" & _
Me.cboReferralSource & "', [DateOfReferral] = '" & Me.txtReferralDate & "', [VisitDate] = '" & Me.txtVisitDate & "', [OpenorClosed] = '" & Me.chkFinalVist & "'," & _
"[Weight] = '" & Me.txtWeight & "', [Height] = '" & Me.txtHeight & "', [BMI] = '" & Me.txtBMI & "', [BloodPressure] = '" & Me.txtBlood & "', [ExerciseLevel] = '" & _
Me.txtExercise & "', [DietLevel] = '" & Me.txtDiet & "', [SelfEsteem] = '" & Me.txtSelf & "', [WaistSize] = '" & Me.txtWaist & "', [Comments] = '" & _
Me.txtComments & "', [Interventions] = '" & Me.cboInterventions & "', [SessionType] = '" & Me.cboSessionType & "', [NHSStaffName] = '" & Me.txtStaffName & "', " & _
"[Arrived] = '" & Me.cboAttendance & "', [ActiveRecord] = -1, [InputBy] = '" & fOSUserName & "', [InputDate] = '" & VBA.Now & "', [InputFlag] = -1 " & _
"WHERE jez_SWM_Visits.VisitID = Forms!frmVisits!txtVisitID "
DoCmd.RunSQL sQRY


My problem is that, when I retrieve a record and amend it. by clicking on my submit button and running this update query it doesnt update the records in my table. why would this be?

OBP
01-13-2009, 03:52 AM
If you copy the start and finish sections of your code as a Select SQL instead of an Append query does it return the Correct Record?
The reason that I ask is that this line
"WHERE jez_SWM_Visits.VisitID = Forms!frmVisits!txtVisitID "
Doesn't look right I would have expected it to be something like
"Where [VisitID] = " & me.txtVisitID
or
"Where [VisitID] = '" & me.txtVisitID & "'"

TedMosby
01-13-2009, 06:58 AM
Excellent Thanks :)