visual basic within Access If...Then

  • Thread starter Thread starter arabella79
  • Start date Start date
A

arabella79

I have a form that's based on a query. I'm trying to make the form
only accept hours worked if there is a pay rate already entered in
another form. If not the form will return a message box notifiying the

user that there is no corresponding pay rate for the hours entered,
then return the fields to null values. The problem is that my code
only works for the A rate and not for the C rate. I think my structure

or my thinking about how to do this wrong. Any help you can provide is

appreciated. Below is the code that I have so far:

Private Sub Form_AfterUpdate()
If ACheck = "bad" Then
MsgBox "You must first enter an A rate in the employee's edit form
before entering hours worked"
Me.asmonday = Null
Me.aomonday = Null
Me.admonday = Null
Me.astuesday = Null
Me.aotuesday = Null
Me.adtuesday = Null
Me.aswednesday = Null
Me.aowednesday = Null
Me.adwednesday = Null
Me.asthursday = Null
Me.aothursday = Null
Me.adthursday = Null
Me.asfriday = Null
Me.aofriday = Null
Me.adfriday = Null
Me.assaturday = Null
Me.aosaturday = Null
Me.adsaturday = Null
Me.assunday = Null
Me.aosunday = Null
Me.adsunday = Null
Me.asx = Null
Me.aox = Null
Me.adx = Null
End If
If CCheck = "bad" Then
MsgBox "You must first enter a C rate in the employee's edit form
before entering hours worked"
Me.csmonday = Null
Me.comonday = Null
Me.cdmonday = Null
Me.cstuesday = Null
Me.cotuesday = Null
Me.cdtuesday = Null
Me.cswednesday = Null
Me.cowednesday = Null
Me.cdwednesday = Null
Me.csthursday = Null
Me.cothursday = Null
Me.cdthursday = Null
Me.csfriday = Null
Me.cofriday = Null
Me.cdfriday = Null
Me.cssaturday = Null
Me.cosaturday = Null
Me.cdsaturday = Null
Me.cssunday = Null
Me.cosunday = Null
Me.cdsunday = Null
Me.csx = Null
Me.cox = Null
Me.cdx = Null
End If
End Sub
 
I suggest you put a breakpoint on the If CCheck... line. When the code stops
and highlights that line, hover your mouse pointer over CCheck to see its
value and compare it to what you think it is. You might be surprised to find
out it isn't "bad"
 
I am not sure from your set-up (ACheck / CCheck???) but for data validation,
the FORM_AfterUpdate Event is certainly too late: the data have been updated
into the Table when the Form_AfterUpdate Event fires.

Suggest you re-post with more details (this Form and the "other" Form) and
describe relevant Fields (from Tables / Query) and Controls on the Form.
 
That sounds like a good idea, I'm pretty new to VB so I was wondering
if you could take a look at the database. It's a zipped file posted
at: http://www.wikiupload.com/comment.php?id=22090. I'm sure there
are a milion ways to improve this, but I'm just trying to clean up a
small part of a massive payroll that's currently being done manually
and with excel spreadsheets ;) Thanks in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top