Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 9th, 2007, 08:39 PM
Authorized User
 
Join Date: Mar 2007
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default If Then Else VBA Flow Help

Hello,

I am having trouble with my VBA code, i require several validation checks on an after update event from a cbo box. My code checks and either enables or disables control depending on the values in other fields.
What i am attempting to do is, if a value is set in my cbo, then check what type of of (claim) this is If Pcent then show (pcent txtbox) If $ then show ($ txtbox) after this i then want to check serval other conditions and enable/disable these controls depending on values in other fields. How do i code this so the after update event will check all of the coditions. At the moment my code stops when a "True Value" is returned.
Here is my code so far

Private Sub Combo36_AfterUpdate()
    ' Find the record that matches the control.
    Dim rs As Object

    Set rs = Me.Recordset.Clone
    rs.FindFirst "[PromotionNo] = '" & Me![Combo36] & "'"
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark

    If IsNull([PcentOfSale]) Then
    Me.PcentOfSale.Visible = False
    Me.SOBValue.Visible = True
    Else
    If Me.PcentOfSale.Value <> 0 Then
    Me.SOBValue.Visible = False
    Me.PcentOfSale.Visible = True
    End If


    If (Forms!frmPromoClaimEnter!Text51 = Extracted) Then
    Command47.Enabled = False
    Else
    Command47.Enabled = True


    If (Forms!frmPromoClaimEnter!ClaimDeadline <= Now()) Then
    Command47.Enabled = True
    Else
    Command47.Enabled = False

    If (Forms!frmPromoClaimEnter!ClaimDeadline > Now()) Then
    Command47.Enabled = False
    Else
    Command47.Enabled = True

    If IsNull(Forms!frmPromoClaimEnter!ClaimDeadline) And IsNull(Forms!frmPromoClaimEnter!frmPromClmLines!Cl mQty) Then
    Command47.Enabled = False
    Else
    Command47.Enabled = True

    If (Forms!frmPromoClaimEnter!Extracted = True) Then
    CRMSAcc.Enabled = False
    Else
    Me.CRMSAcc.Enabled = True


    If (Forms!frmPromoClaimEnter!Extracted = True) Then
    frmPromClmLines.Enabled = False
    Else
    Me.frmPromClmLines.Enabled = True

 
Old May 10th, 2007, 06:29 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Why are you not using End If at the end of each statement? Like:

If (Forms!frmPromoClaimEnter!Text51 = Extracted) Then
    Command47.Enabled = False
    Else
    Command47.Enabled = True
End If

If (Forms!frmPromoClaimEnter!ClaimDeadline <= Now()) Then
    Command47.Enabled = True
Else
    Command47.Enabled = False
End If

Your business rules are very important, so it would be difficult to understand what flow control you want if you are posting vague business rules. I think if you explicitly state the business rules, the flow control will take care of itself. As it is, it looks like all of these should be stand alone If Then Else End If blocks.

Did any of that help? Try posting the exact rules.

mmcdonal
 
Old May 10th, 2007, 06:35 PM
Authorized User
 
Join Date: Mar 2007
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi mmcdonal,

Point taken with business rules, the code is flow as needed, i did neglect to copy over the end if 's when posting this, having said this i followed your advice and found one of my rules didn't have the end if at the end of that rule, rather it was at the end of the entire statement, so if a condition of that rule wasn't passed the code was stopping. I have now cleaned up this code and all rules are now being checked and passed to the next rule.

Thanks Again

Cheers







Similar Threads
Thread Thread Starter Forum Replies Last Post
how to slow down this flow jjk2 Beginning VB 6 8 January 28th, 2008 07:12 PM
control flow aranjan ASP.NET 1.0 and 1.1 Professional 0 March 29th, 2007 12:44 PM
flow of an object catchrohith .NET Framework 2.0 0 November 18th, 2006 01:04 AM
Flow of the Program ? pandian Java Basics 2 March 20th, 2006 11:07 PM
Flow Control shmacgregor VS.NET 2002/2003 6 February 25th, 2004 01:05 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.