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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I would like to go into a form and

Status
Not open for further replies.

sanders720

Programmer
Aug 2, 2001
421
0
0
US
I would like to go into a form and change the data, but prior to doing this I would like to remember the old data and store it into a field. I am doing both a select and an update query here, but I'm not sure this is the correct approach or syntax. Certainly, I could just reat the form field txtQTY into the field OldQtyFlag.

Additionally, I am slightly confused as to which function to perform this command under. Got Focus, Change, etc. Do you know if there is a good reference for the exactness of when these events occur.


Private Sub txtQTY_GotFocus()

Dim db As Database
Dim sql As String
Dim rst As Recordset
Dim xQTY As Integer

'sql = "UPDATE tblBOM SET OldQtyFlag = " & numQTY & " WHERE JobNo = " & Me.JobNo.Value & " AND SubAssy= '" & Me.SubAssy.Value & "' and PartNo = '" & Me.PartNo.Value & "'"

sql = "SELECT QTY FROM tblBOM WHERE JobNo = " & Me.JobNo.Value & " AND SubAssy= '" & Me.SubAssy.Value & "' and PartMo = '" & Me.PartNo.Value & "'"
Set rst = CurrentDb.OpenRecordset(sql)
xQTY = rst("QTY")

With rst

db.Execute "UPDATE tblBOM SET OldQtyFlag = xQTY"

End With

rst.Close
Set rst = Nothing

End Sub
 
If you're using bound controls, look up the OldValue property in the help file. Access may be already doing what you want.

Luther
 
I'm sorry. It was late.

I believed that you were trying to save the original value of form controls bound to a data table or query prior to editing those values. In foxpro days you would've used Scatter / Gather.

Anyway, for bound controls, Access does this for you in the form of the OldValue property. This property value is then available to you (read only) in whatever post editing event you choose (maybe validation or whatever).

If this isn't what you were trying to accomplish then I've misunderstood your intent (in which case these are just the ramblings of someone waiting on their teenagers to need rides home).

As to the event reference, looking up event in the index of the help file gets, among other things in a long list of entrys, events order of. This is a note I copied from the help file:

Note You can see the order in which events occur on a form by opening the ShowEvents form in the Orders sample application. When events occur on the ShowEvents form ¾ for example, when you open the form or move to a new record ¾ the EventHistory form lists the events in the order in which they occur.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top