Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Jun 2002
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Visual Basic Labels (6.0)

    I am having a problem trying to refer in a VB sub routine to MS Access fields. This is my first attempt at VB!

    I have a Table called "Carrier" with a Form called "Data Entry Master"
    I have fields called "$Premium", and "% Comm", and "CBP Commission"

    I wrote the following simple routine:

    Sub Text195_Click()
    If Form_DataEntryMaster![$Premium] > 0 And Form_DataEntryMaster![%Comm] > 0 Then GoTo a1
    a1: Form_DataEntryMaster![CBP Commission] = Form_DataEntryMaster![$Premium] * Form_DataEntryMaster![%Comm]/100
    End Sub

    If any one can set me off down the correct path I would appreciate it.

    Thanks

    Peter Lyons

  2. #2
    2 Star Lounger
    Join Date
    Feb 2002
    Location
    Blacktown, Sydney, New South Wales, Australia
    Posts
    175
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Visual Basic Labels (6.0)

    I dont think you need a sub routine
    Try a totally different approach.

    Set 0 (zero) as the default values in [$Premium] and [%Comm] (I assume that negative values are not valid)
    As the data source in [CBP Commission] enter this formula
    =[$Premium] * [%Comm] / 100
    If one of these two fields is zero, the result will be zero, Which is what I think you are trying to achieve

  3. #3
    New Lounger
    Join Date
    Jun 2002
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Visual Basic Labels (6.0)

    Hi Devious Dude
    Thanks for quick response.
    Reason I need sub routine is:
    For some records I need to do calculation for CBP Commission
    for other records I need to overide calculation with manual entry.
    Believe my problem just is with field naming nomenclature
    Thanks
    Peter Lyons

  4. #4
    2 Star Lounger
    Join Date
    Feb 2002
    Location
    Blacktown, Sydney, New South Wales, Australia
    Posts
    175
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Visual Basic Labels (6.0)

    OK, try looking up the Me! syntax in Help

    This may solve problem

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Visual Basic Labels (6.0)

    Why would you want to use a Click event of a textbox to perform your calculation? You can't have an updateable calculated field, so you do need a routine for the calculation or calculations, but where are you trying to call it from and under what circumstances? How were you planning to handle fields that already have values in them? And why are you storing calculated values in the first place? If you have the two values used to calculate them already in the table, there is no purpose in calculating the result as well.

    Please do yourself and us a favor and get rid of the goto in your code. Gotos are legacies of procedural languages and they do nothing but make event driven code hard to read and debug. They're also a good way to get your code so tangled up that it steps on itself. You can't avoid GoTo with error handlers, but you can and should avoid it anywhere else.
    Charlotte

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •