Results 1 to 6 of 6
  1. #1
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544

    Question Force numeric value

    So I have a combo box that is passing a value to a variable that must be defined as integer. The combo box is bound on an Autonumber field. However, when a null value is passed to the variable it is still passing a "" vs. 0. I am sure there is code to force the value of 0 to be passed if the value is null. I have included the piece of code for reference (varMetricNumber is the one I am concerned with). Thanks in advance.

    Code:
        Dim varMetricName, varDataNumber
        Dim varMetricNumber As Integer
        
        varDataNumber = Form_frmFindMetric.cboDatamartName.Value
        varMetricName = Form_frmFindMetric.cboMetricName.Value
        varMetricNumber = Form_frmFindMetric.cboMetricNumber.Value


  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Check out the Nz() function.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Tried Nz() and I'm still getting "type mismatch".

    Code:
    varMetricNumber = Nz(Form_frmFindMetric.cboMetricNumber.Value, 0)

  4. #4
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    varMetricNumber = cint(Nz(Form_frmFindMetric.cboMetricNumber.Value, "0"))

    and you may need to change
    varDataNumber = Form_frmFindMetric.cboDatamartName.Value
    to
    varDataNumber = cint(Form_frmFindMetric.cboDatamartName.Value)
    as well

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    What does the form control contain?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    That didn't solve the issue either...Still returned a "type mismatch" error. I gave up and just used the below IF statement. Thanks for the help.

    Code:
        If Form_frmFindMetric.cboMetricNumber.Value <> "" Then
            varMetricNumber = Form_frmFindMetric.cboMetricNumber.Value
        End If

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Split Numeric Data out of Irregular Text Field
    By nathanielban in forum Queries
    Replies: 6
    Last Post: 12-21-2010, 10:30 AM
  2. Updating Numeric Values
    By dssrun in forum Queries
    Replies: 9
    Last Post: 11-24-2010, 11:20 AM
  3. Recordset not showing alpha-numeric entries
    By rayhawk in forum Access
    Replies: 9
    Last Post: 10-29-2010, 08:15 AM
  4. order by - string and numeric
    By pen in forum Queries
    Replies: 10
    Last Post: 05-20-2009, 06:29 AM
  5. Numeric value out of range (null)
    By PPCMIS2009 in forum Queries
    Replies: 0
    Last Post: 02-03-2009, 11:01 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums