Solved

If VBYes then remove some info

Posted on 2006-06-22
12
780 Views
Last Modified: 2012-08-14
This is part of a Before Update event:

            If Me.CertificationType.Value = "Permanent Decertification" Then
                Me.Visible = False
                If MsgBox("You have selected Permanent Decertification." & vbCrLf & vbCrLf _
                   & "By making this selection you will be removing dates pertinent to this " _
                   & "individuals CPRP Certification process." & vbCrLf & vbCrLf _
                   & "THIS REMOVAL ON INFORMATION CAN NOT BE UNDONE.  Do you wish to continue " _
                   & "with this selection?", vbYesNo) = vbYes Then
                   
                    Set PDQrs = db.OpenRecordset("tblDatesRemoved")
                   
                    With PDQrs
                        .AddNew
                        !EmpNo = Me.EmpNo
                        !CertificationType = Me.CertificationType.Value
                        !InitialInterview = Me.InitialInterview
                        !Date3180ToCOReview = Me.Date3180ToCOReview
                        !Date3180ToHR = Me.Date3180ToHR
                        !Date3180FromHR = Me.Date3180FromHR
                        !Date3180ToClinic = Me.Date3180ToClinic
                        !Date3180FromClinic = Me.Date3180FromClinic
                        !Date3180ToCOFinal = Me.Date3180ToCOFinal
                        !CertificationDate = Me.CertificationDate
                        .Update
                    End With
                   
                    Set PDQrs = Nothing
                   
                    Me.CertificationType = ""
                    Me.InitialInterview = ""
                    Me.Date3180ToCOReview = ""
                    Me.Date3180ToHR = ""
                    Me.Date3180FromHR = ""
                    Me.Date3180ToClinic = ""
                    Me.Date3180FromClinic = ""
                    Me.Date3180ToCOFinal = ""
                    Me.CertificationDate = ""
                   
                    Me.Visible = True
                   
Everything works great...until I want to reset the values of other controls on my form.

What do I need to do to make this work?

Thanks!
Lena
0
Comment
Question by:LenaWood
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 27

Expert Comment

by:jjafferr
ID: 16962166
Hi LenaWood,

You can reset the string controls by assigning "" to them,
but for numbers, you have to assign a 0 (zero)

jaffer
0
 
LVL 27

Expert Comment

by:jjafferr
ID: 16962182
I would suggest you putting a remark on all the Reset code items, then checking them 1 at a time
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 16962184
use the Tag property of the controls.

dim ctl as control
for each ctl i me.controls
  if ctl.tag="somevalue" then
     ctl.name=""
  end if

next
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 16962209
Hey Lena

You'd not change the values of controls in the active form in a BeforeUpdate event.
Normally you'd test then - make a decision to proceed or not, and then make changes afterwards.
0
 
LVL 10

Author Comment

by:LenaWood
ID: 16962263
OK....my recordset works and all the information is put into the table.  What I can't do is remove the dates from my controls on my form.

I have tried Me.CertificationType = Null and Me.CertificationType = "" with no luck.  I have even made sure that zero lengths are allowed. (They weren't but changing it didn't help).  CertificationType is a text field.

The error message I get is:

The macro or function set to the Before Update or Validation Rule property for this field is preventing Microsoft Access from saving the data in the field.

I am looking at this knowing I should know how to do this, but it all is looking kinda foriegn to me.  Thank goodness the weekend is almost here.

Lena
0
 
LVL 10

Author Comment

by:LenaWood
ID: 16962281
LPurvis - I thought I was testing by asking the question if they want to proceed.  If they say yes I want to proceed.  It is the proceeding part that I am having trouble with.  I am starting to really HATE this database haha.

Lena
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 16962330
Is it a control or the form's beforeupdate event we're talking about?
0
 
LVL 10

Author Comment

by:LenaWood
ID: 16962374
The code I pasted is on a controls before update event.  I think I am trying to automate far too much!

Lena
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 16962393
No - that should be OK.

But in what way is it going wrong?
Where are you getting an error - and which error is it?

Are the specified fields allowed to be a zero length string?
(I'd always set mine to Null.  Always always always).

Did I mention always?
0
 
LVL 10

Author Comment

by:LenaWood
ID: 16962446
Error is:

The macro or function set to the Before Update or Validation Rule property for this field is preventing Microsoft Access from saving the data in the field.

It won't change the values to "" or Null

Yes, they are allowed to be zero length.  All of them are dates except one, and I didn't see an allow Zero length on the date fields in the table.

I have it working, just not sure it is how I should have done it.  I created a publically declared blnChangeDates as a boolean.  When the form is opened I set it to false.  When I run the code pasted above instead of changing the dates then, I changed blnChangeDates to true.  On the button that closes that form, I have it check for the value of blnChangeDates and if it is true, I have it set the values of those controls to "" (but will ALWAYS change it to null).

Just not sure what I am doing wrong in the first place.
Lena
0
 
LVL 44

Accepted Solution

by:
Leigh Purvis earned 500 total points
ID: 16962473
I'd do exactly as you describe - but set your boolean flag to true in the BeforeUpdate - and perform your changes in the Afterupdate event based on the state of that flag.
(Remember to reset the flag in the afterupdate event too ;-)
0
 
LVL 10

Author Comment

by:LenaWood
ID: 16962805
I tried this in the afterupdate event (of the control) and had no luck with it working.  Probably something that I did wrong.  I will try it again.

Thanks!
Lena
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now