Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ms access error handling

Posted on 2013-12-11
5
Medium Priority
?
240 Views
Last Modified: 2014-03-18
I keep getting a runtime error of 94 when I make the first select in the code below. How  do I create a error handle to capture null value or blank values.

Private Function calculateTotal(v1, v2)
    Dim iTier1 As Integer  ' number in control name for units sold controls - Tier1, Tier2, ...
    Dim iTier2 As Integer
    Dim cGSAR As Currency ' total per line
    Dim i As Integer 'counter for lines considered

THIS IS WHERE I BELIEVE I GET THE ERROR - I am making the first selection from combox.
 
    iTier1 = Right(v1, 1) ' gives 1 for US1, 2 for US2 and so on
    iTier2 = Right(v2, 1)
    cGSAR = 0
    For i = iTier1 To iTier2
        cGSAR = cGSAR + Me.Controls("Tier" & i)
    Next
   
    calculateTotal = cGSAR
End Function
0
Comment
Question by:deefel
[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
  • 2
  • 2
5 Comments
 
LVL 85
ID: 39710840
You can use the Nz function:

If Nz(v1, "") <> "" Then
    iTier1 = Right(v1, 1) ' gives 1 for US1, 2 for US2 and so on
End If
If Nz(v2, "") <> "" Then
    iTier2 = Right(v2, 1)
End If
0
 
LVL 96

Expert Comment

by:Lee W, MVP
ID: 39710915
You have a number of ways.

One option would be:
'First, set iTier1 to a default value - empty, 0, whatever 
iTier1 = "0" 'Or something else (including "") since it's otherwise not valid.

'Then test if v1 meets the criteria necessary to assign a different value to iTier1 - 
'leave the default if not, otherwise, make iTier1 the new value.
If IsNull(v1) = False Then
   If Len(v1) > 0 Then
      If IsNumeric(v1) = True Then
         iTier1 = Right(v1, 1) ' gives 1 for US1, 2 for US2 and so on
      End If
   End If
End If

Open in new window

0
 

Author Comment

by:deefel
ID: 39712309
I tried the code, but still got the error message ~ it could be I put the code in th wrong place.  I have attached a sample database and a screenshot.  When in the database select from the drop down for Tier1/PL 1a value ~ this is where the error happens
example-1.zip
screen-shot.xlsx
0
 

Author Comment

by:deefel
ID: 39713543
Could I please get help with runtime error.  see example-1 database.  thanks
0
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 1200 total points
ID: 39716728
You can't run CalculateTotal if either incoming value is NULL, so just check for that before you get started with the code:

Private Function calculateTotal(v1, v2)

    If Nz(v1, "") = "" Or Nz(v2, "") = "" Then
        Exit Function
    End If


    Dim iTier1 As Integer  ' number in control name for units sold controls - Tier1, Tier2, ...
    Dim iTier2 As Integer
    Dim cGSAR  As Currency    ' total per line
    Dim i      As Integer    'counter for lines considered


    iTier1 = Right(v1, 1)    ' gives 1 for US1, 2 for US2 and so on
    iTier2 = Right(v2, 1)
    cGSAR = 0
    For i = iTier1 To iTier2
        cGSAR = cGSAR + Me.Controls("Tier" & i)
    Next

    calculateTotal = cGSAR
End Function

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

730 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