Solved

If VBYes then remove some info

Posted on 2006-06-22
12
791 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

707 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