473,387 Members | 1,548 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,387 software developers and data experts.

Reverting To Old Value if Validation Fails

I am developing an application for a Pathology Lab. There are Batches
(BatchID) which contain multiple Samples (SampleID), and there can be
multiple tests run from the same Sample, thus there can be multiple records
with the same SampleID.

The Basic Data for the samples is entered when the batch is set up
initially. There are also 3 results textboxes which will hold the results
of the Pathology tests. If the user realizes that there is something wrong
with the Basic Data and decides to change it, they will need to decide
whether to apply the change to "THIS SampleID ONLY "(across several tests)
or "ALL RECORDS IN THE BATCH." Regardless they do not want to copy the
Results textboxes from test to test or batch to batch.

To change the data, the user clicks on the "Change Data" button, which
unlocks the textboxes which can be changed. After the change is made to each
control, the user is then prompted to apply it to the Batch or Sample, as I
described above. The InputBox has a textbox for selecting either B or S or
they can click the Cancel button.

The code I have written is shown below. I put it in control_Before Update,
because if I put it in control_Change then the Inputbox pops up with every
character that is entered. But the problem I am having is that if the User
decides to Cancel the change (or inputs a letter other than B or S), I would
like it to revert back to the original value.

Using CancelUpdate cancels the routine from happening, but the current
record still remains changed.

If I put this code in the form_BeforeUpdate section then how do I get around
it applying this when the user has put something in one of the Results
boxes - which I want to remain in ONLY the current record.

Is there a better way to handle this? (See Case"" or Case Else below):

Private Sub RefrigFreezerNo_BeforeUpdate(Cancel As Integer)

Dim strQuery As String
Dim strSQL As String
Dim rsA As dao.Recordset
Dim Response As String
Dim rsC As dao.Recordset 'I put this in to see if using Recordset clone
would work, but it doesn't seem to

Set rsC = Me.RecordsetClone

Response = InputBox("What records do you want to change?" & vbNewLine &
vbNewLine & _
" All records in the Batch? - Type 'B'" & vbNewLine & _
" or" & vbNewLine & _
" Only the records with this SampleID? - Type 'S'", "Change
Info")
Select Case Response

Case "s"
'this query chenges the data in every record with the same SampleID
strQuery = "qryOpenChangeSamples"
strSQL = "SELECT * from qryChangeSampleInfo WHERE SampleID= " &
Me.SampleID
ChangeQueryDef strQuery, strSQL
Set rsA = CurrentDb.OpenRecordset("qryOpenChangeSamples",
dbOpenDynaset)

rsA.LockEdits = False
rsA.MoveFirst
Do Until rsA.EOF

rsA.Edit
rsA![RefrigFreezerNo] = Me.[RefrigFreezerNo]
rsA.Update

rsA.MoveNext
Loop
Case "b"
'this query applies to all records in the batch
strQuery = "qryOpenChangeSamples"
strSQL = "SELECT * from qryChangeSampleInfo WHERE BatchID= " &
Me.BatchID
ChangeQueryDef strQuery, strSQL
Set rsA = CurrentDb.OpenRecordset("qryOpenChangeSamples",
dbOpenDynaset)

rsA.LockEdits = False
rsA.MoveFirst
Do Until rsA.EOF

rsA.Edit
rsA![RefrigFreezerNo] = Me.[RefrigFreezerNo]
rsA.Update

rsA.MoveNext
Loop

Case "" 'User clicks the Cancel button
'this is one way I tried, but it dodn't seem to cancel in the
current record
rsC.Close
Exit Sub

Case Else 'User inputs another letter
'this is a second warning to enter the correct letters
MsgBox "Enter a B (Batch) or S (Sample)"
Response = InputBox("What records do you want to change?" &
vbNewLine & vbNewLine & _
" All records in the Batch? - Type 'B'" & vbNewLine & _
" or" & vbNewLine & _
" Only the records with this SampleID? - Type 'S'", "Change
Info")

'this is a dummy query to create a recordset on which to cancel the update.
(or should I use the original me.recordset?)
strQuery = "qryOpenChangeSamples"
strSQL = "SELECT * from qryChangeSampleInfo WHERE BatchID= " &
Me.BatchID
ChangeQueryDef strQuery, strSQL
Set rsC = CurrentDb.OpenRecordset("qryOpenChangeSamples",
dbOpenDynaset)

rsC.LockEdits = True
rsC.Edit
rsC!RefrigFreezerNo=Me.RefrigFreezerNo
rsc.CancelUpdate
Exit Sub
End Select

rsA.Close: Set rsA = Nothing
rsC.close:Set rsC=Nothing

End Sub
Thanks in advance to whomever helps me out of this problem!

Nov 12 '05 #1
0 1651

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

Similar topics

4
by: bnp | last post by:
Hi All, I am quite new the JavaScript. Basically I am a C++ programmer, but now I am working on JavaScript since last 5 days. I have a problem regarding the form validation. I have created a...
0
by: DBQueen | last post by:
I am developing an application for a Pathology Lab. There are Batches (BatchID) which contain multiple Samples (SampleID), and there can be multiple tests run from the same Sample, thus there can...
0
by: Brian Conway | last post by:
I am having some validation and insertion problems. I am using a date picker that takes the selected date and puts it to ("dd-MMM-yyyy") format, as this was the only format that Oracle would...
3
by: Gary Varga | last post by:
In the file WebUIValidation.js, when a postback that doesn't fail the validation has a javascript error saying summary is undefined in the ValidationSummaryOnSubmit function....
5
by: siaj | last post by:
Hello, I have a javascript function for a validation in the HTML page of the asp.Net page.. I call this function in a Savebutton click When the validation fails No postback should happen ( ie...
8
by: Nathan Sokalski | last post by:
I have a System.Web.UI.HtmlControls.HtmlInputFile control that I use to submit files. After the file is successfully submitted, I want the field to be reset so that the user knows the file was...
0
by: ashoksharma2621 | last post by:
I'm using Xerces-J-2.6.2 it barks at me with org.xml.sax.SAXParseException: InvalidRegex: Pattern value '?(\d+|\d+(\.\d+)?%)(,\s*?(\d+|\d+(\.\d+)?%))*' is not a valid regular expression. The...
2
by: Steve Richter | last post by:
getting this "potentially dangerous Request.Form value was detected" exception with a textbox which I have populated with some source code. I think I am getting the exception when I click OK on...
2
by: Pselus | last post by:
I have a form that is built pretty much entirely at run time. I load a collection of Categories which have multiple Plans. Each Plan has a RadioButton. Each Category has a single PriceTag...
8
by: Bryan | last post by:
I want my business objects to be able to do this: class Person(base): def __init__(self): self.name = None @base.validator def validate_name(self): if not self.name: return
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.