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

    Question Check for no value


    I have a form that loads in the background (Form1) and I assign the value from one of the text boxes in Form1 to a variable (var1) in my main form (formMain). Form1 is based on a query that has the potential of returning nothing. When I try to do a simple var1 = form1.textbox.value I get the error "you entered an expression that has no value.". Is there a way to check for no value? If there is no value I simply want to make var1 = 0. I tried
    Code:
    if form1.textbox.value is null then
         var1 = 0
    else
         var1 = form1.textbox.value
    end if
    However, that did not work and I got the same error.

  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
    I use:

    If Len(Whatever & vbNullString) = 0 Then

    which tests for both Null and a Zero Length String. Given what you're doing, you could simply use the Nz() function:

    Var1 = Nz(Whatever, 0)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Nz() function did not work. Still getting the error message "You entered an expression that has no value".

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    It would help to see exactly what you tried. If the form might have a ZLS, try the first test.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    This is the code I am using. It worked...The interesting this is if you'll notice this is copied directly from my code...I am not aware that "Whatever" is an operator...

    Code:
    If Len(Whatever & vbNullString) = 0 Then
            varAging = 0
        Else
            varAging = Form_SfrmARsAge.txtAgePercent.Value
        End If

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    There isn't; "Whatever" was intended to be replaced by your form reference. I said it that way because it could be a variable, form reference, etc.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Ok, I feel pretty stupid right about now! So the code should read as below:

    Code:
    If Len(form.textbox.value & vbNullString) = 0 Then
            varAging = 0
        Else
            varAging = Form_SfrmARsAge.txtAgePercent.Value
        End If

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Yes, presuming that's a valid way to reference the form. It doesn't look like it to me, but I know there are multiple ways. I use these:

    Forms Refer to Form and Subform properties and controls
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Well...unfortunately this is not working now either....

    Code:
        If Len(Form_SfrmARsAge.txtAgePercent.Value & vbNullString) = 0 Then
            varAging = 0
        Else
            varAging = Form_SfrmARsAge.txtAgePercent.Value
        End If

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The name implies that's a subform; is it? If so, see the link for proper syntax. If that doesn't help, can you post the db?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    I tried the referenc you suggested:

    Code:
        If Len(Forms!frmCollStats!SfrmARsAge.Form.txtAgePercent.Value & vbNullString) = 0 Then
            varAging = 0
        Else
            varAging = Form_SfrmARsAge.txtAgePercent.Value
        End If
    Unfortunately I cannot post the DB. Let me see if I can explain my dilemma again.

    I have a Query that returns results. It is possible for the query to return no results and therefore when the subform loads it loads blank (text boxes do not display or anything). When that occurs I want my variable to be assigned 0, otherwise I want my variable to be assigned the value of the text box on the form. I guess instead of using a form I could run my SQL out of VBA but I'm not well versed in that area. My SQL statement is below.

    Code:
    SELECT QryZZZOver2yrsOld.Emp, QryZZZOver2yrsOld.Balance AS Over2Yr, Sum(TblARReportYTDReport.EndBal) AS YTDEndBal, [Over2Yr]/[YTDEndBal] AS YTDPct
    FROM QryZZZOver2yrsOld INNER JOIN TblARReportYTDReport ON QryZZZOver2yrsOld.Emp = TblARReportYTDReport.RACF_No
    GROUP BY QryZZZOver2yrsOld.Emp, QryZZZOver2yrsOld.Balance
    HAVING (((QryZZZOver2yrsOld.Emp)=[Forms]![FrmCollStats]![cboRVNum]));

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Ah, the empty subform problem. I use this:

    http://www.mvps.org/access/forms/frm0022.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    That was very helpful. Thanks a lot!

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

Similar Threads

  1. Check of the students every day
    By carstenhdk in forum Forms
    Replies: 11
    Last Post: 05-23-2010, 04:33 AM
  2. To check or Un-Check all Boxes in a form
    By devcon in forum Forms
    Replies: 7
    Last Post: 05-01-2010, 12:03 AM
  3. Check box
    By nashr1928 in forum Forms
    Replies: 5
    Last Post: 04-21-2010, 02:37 PM
  4. check box criteria?
    By kzoll@mindspring.com in forum Queries
    Replies: 3
    Last Post: 11-24-2009, 09:43 AM
  5. Check Box Value
    By mulefeathers in forum Programming
    Replies: 4
    Last Post: 10-09-2009, 08:31 PM

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