473,396 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with OldValue


I am running some code to validate the entry made into a form called
NumberOfSamples. If validation fails, then I want to revert back to the old
value. I keep getting an error msg that says:

"Run-time Error 2115: The macro or function set to the Before Update or
Validation Rule property for this field is preventing Access from saving the
data in the field." Debug points to the oldvalue statement. What might be
the problem? See code below.....

Thanks for your help!
Andi Plotsky
Private Sub NumberOfSamples_BeforeUpdate(Cancel As Integer)
Dim rsA As DAO.Recordset
Dim strQuery As String
Dim strSQL As String
Dim numrec As Integer
Dim varTestname As String

Set frmcurrent = Me.Form
varTestname = SelectTestsLast(frmcurrent)
Debug.Print "vartestname= "; varTestname

'Select 1 of each SampleID to count the current number of samples:
strQuery = "qryOpenSamples"
strSQL = "SELECT SampleID,[Testname],BatchID, SubjectName,HistNo,[Sample
Type],RefrigFreezerNo,ShelfNo, DateOfSample,TimeOfSample FROM qryblue WHERE
BatchID=" & Me.BatchID & " AND Testname=" & "'" & varTestname & "'" & "
order by SampleID"
ChangeQueryDef strQuery, strSQL

Set rsA = CurrentDb.OpenRecordset("qryOpenSamples", dbOpenDynaset)

rsA.MoveFirst
rsA.MoveLast
numrec = rsA.RecordCount 'the number of Samples in the batch previously
Debug.Print "numrec= "; numrec

If NumberOfSamples < numrec Then
MsgBox "Oops! The new Number of Samples is LESS than the current
Number of Samples. If you want to DELETE reccords, start at the Main Menu."
NumberOfSamples.Value = NumberOfSamples.OldValue
Exit Sub
End If

If NumberOfSamples = numrec Then
MsgBox "You have not changed the Number of Samples"
NumberOfSamples.Value = NumberOfSamples.OldValue
Exit Sub
End If

rsA.Close: Set rsA = Nothing

End Sub
--
Andi Plotsky
IRIS, LLC
Nov 12 '05 #1
2 6159
Andi Plotsky wrote:
I am running some code to validate the entry made into a form called
NumberOfSamples. If validation fails, then I want to revert back to the old
value. I keep getting an error msg that says:

"Run-time Error 2115: The macro or function set to the Before Update or
Validation Rule property for this field is preventing Access from saving the
data in the field." Debug points to the oldvalue statement. What might be
the problem? See code below.....

Thanks for your help!
Andi Plotsky
Private Sub NumberOfSamples_BeforeUpdate(Cancel As Integer)
Dim rsA As DAO.Recordset
Dim strQuery As String
Dim strSQL As String
Dim numrec As Integer
Dim varTestname As String

Set frmcurrent = Me.Form
varTestname = SelectTestsLast(frmcurrent)
Debug.Print "vartestname= "; varTestname

'Select 1 of each SampleID to count the current number of samples:
strQuery = "qryOpenSamples"
strSQL = "SELECT SampleID,[Testname],BatchID, SubjectName,HistNo,[Sample
Type],RefrigFreezerNo,ShelfNo, DateOfSample,TimeOfSample FROM qryblue WHERE
BatchID=" & Me.BatchID & " AND Testname=" & "'" & varTestname & "'" & "
order by SampleID"
ChangeQueryDef strQuery, strSQL

Set rsA = CurrentDb.OpenRecordset("qryOpenSamples", dbOpenDynaset)

rsA.MoveFirst
rsA.MoveLast
numrec = rsA.RecordCount 'the number of Samples in the batch previously
Debug.Print "numrec= "; numrec

If NumberOfSamples < numrec Then
MsgBox "Oops! The new Number of Samples is LESS than the current
Number of Samples. If you want to DELETE reccords, start at the Main Menu."
NumberOfSamples.Value = NumberOfSamples.OldValue
Exit Sub
End If

If NumberOfSamples = numrec Then
MsgBox "You have not changed the Number of Samples"
NumberOfSamples.Value = NumberOfSamples.OldValue
Exit Sub
End If

rsA.Close: Set rsA = Nothing

End Sub

See if this works. Apply where necessary

If NumberOfSamples = numrec Then
MsgBox "You have not changed the Number of Samples"
me.NumberOfSamples.Undo
Cancel = True
End If

Nov 12 '05 #2
It worked - thanks!!
"Salad" <oi*@vinegar.com> wrote in message
news:S_*****************@newsread2.news.pas.earthl ink.net...
Andi Plotsky wrote:
I am running some code to validate the entry made into a form called
NumberOfSamples. If validation fails, then I want to revert back to the old value. I keep getting an error msg that says:

"Run-time Error 2115: The macro or function set to the Before Update or
Validation Rule property for this field is preventing Access from saving the data in the field." Debug points to the oldvalue statement. What might be the problem? See code below.....

Thanks for your help!
Andi Plotsky
Private Sub NumberOfSamples_BeforeUpdate(Cancel As Integer)
Dim rsA As DAO.Recordset
Dim strQuery As String
Dim strSQL As String
Dim numrec As Integer
Dim varTestname As String

Set frmcurrent = Me.Form
varTestname = SelectTestsLast(frmcurrent)
Debug.Print "vartestname= "; varTestname

'Select 1 of each SampleID to count the current number of samples:
strQuery = "qryOpenSamples"
strSQL = "SELECT SampleID,[Testname],BatchID, SubjectName,HistNo,[Sample Type],RefrigFreezerNo,ShelfNo, DateOfSample,TimeOfSample FROM qryblue WHERE BatchID=" & Me.BatchID & " AND Testname=" & "'" & varTestname & "'" & "
order by SampleID"
ChangeQueryDef strQuery, strSQL

Set rsA = CurrentDb.OpenRecordset("qryOpenSamples", dbOpenDynaset)

rsA.MoveFirst
rsA.MoveLast
numrec = rsA.RecordCount 'the number of Samples in the batch previously Debug.Print "numrec= "; numrec

If NumberOfSamples < numrec Then
MsgBox "Oops! The new Number of Samples is LESS than the current Number of Samples. If you want to DELETE reccords, start at the Main Menu." NumberOfSamples.Value = NumberOfSamples.OldValue
Exit Sub
End If

If NumberOfSamples = numrec Then
MsgBox "You have not changed the Number of Samples"
NumberOfSamples.Value = NumberOfSamples.OldValue
Exit Sub
End If

rsA.Close: Set rsA = Nothing

End Sub

See if this works. Apply where necessary

If NumberOfSamples = numrec Then
MsgBox "You have not changed the Number of Samples"
me.NumberOfSamples.Undo
Cancel = True
End If

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: BUSHII | last post by:
I have little problem and I dont have any idea how to make my trigger. I have table MyTable where I have many column with almost same name and same type (Grp1,Grp2,Grp3,Grp4...Grp50 char(1))....
1
by: Andi Plotsky | last post by:
I am running some code to validate the entry made into a form called NumberOfSamples. If validation fails, then I want to revert back to the old value. I keep getting an error msg that says: ...
0
by: Jongmin | last post by:
I met a problem when implementing IBindingList interface. I made CustomerList class, copied from MSDN, to implement CollectionBase and IBindingList. My problem took place after setting...
5
by: Jason Huang | last post by:
Hi, The SqlParameter myPM =new SqlParameter("@Address", txtAddress.Text) is working for update, but SqlParameter myPM =new SqlParameter ("@Address",SqlDbType.NVarChar,90,txtAddress.Text) is...
5
by: Dugo | last post by:
In Access 2003, I have a form (continuous form view) with several text boxes. The text boxes are not bound to a table since the layout of the form differs greatly from the structure of the...
1
by: gazelle04 | last post by:
I have these on BeforeUpdate event of a control If Me.txtAddress.Value <> Me.txtAddress.OldValue Then Me.txtGenInfo_UpdatedOn = Now Me.txtGenInfo_UpdatedBy = fOSUserName ...
2
by: Keith Wilby | last post by:
In A2k3 is it possible to determine if the OldValue property for a check box exists using code? Thanks. Keith.
7
by: Richard Sherratt | last post by:
I'm trying to stop users deleting an existing value in a field. If they go to an existing record and hit delete, I want to give an error message and reverse the change. The BeforeUpdate event is...
8
by: Avi | last post by:
Hi all, I'm using string Replace(string oldValue, string newValue) and would like it to replace only full words that matches oldValue and not when oldValue is a substring of a larger word. ...
1
by: Allen Browne | last post by:
Testing if the new value is different from the old one avoids giving the message in these cases: a) It's a new record (so there was no old value.) b) No customer was specified previously (so the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.