Results 1 to 6 of 6
  1. #1
    dvgef2 is offline Novice
    Windows 8 Access 2013
    Join Date
    Mar 2013
    Posts
    25

    Simple Code for a Command Button

    Good Afternoon Everyone,

    I try to keep code to a minimum because it just never seems to work when I do it but does anyone see anything wrong with this code?

    If Me.CustNum = Null Then
    DoCmd.OpenReport "rptCertOfCompBlank", acViewPreview


    Else
    DoCmd.OpenReport "rptCertOfComp", acViewPreview, , "intCustomerNum =" & Me.intCustomerNum
    End If


    These are the commands I used for a command button to open a report. If the form is at the "New Record" stage, I would like it to open a blank Certificate of Completion form and if it is at a completed record then I want it to open the Certificate of Completion with all the data filled in each line. Many salesmen like the blank form so that they can just write in the information at their convenience while other more elitist types like to have it all typed in professionally. It is strange that the more complicated line after the 'Else' works fine, it is only when it is at the 'New Record' Mode that I get errors instead of a blank form. The error is some type of syntax error that refers to the line after the 'Else' but again, it should be operating off the first 'DoCmd' line unless I am totally screwed up which is not beyond the realm!

    Me.CustNum is Null according to the watch and so I would think that the report "rptCertOfCompBlank" would open but it jumps right over that line to the 'Else' and tries to perform that next command. It is as if the first "DoCmd.OpenReport" line does not exist. I would understand it if the "Me.CustNum = Null" was not true. But it is true and so I am missing something....well I am probably missing a lot but I would still like to get this to work.

    I hope I have put enough information in and I would appreciate it if anyone has any suggestions. Thanks and have a good day!

    Dave

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    FYI: *Nothing* is ever equal to Null, including Null. That's why VBA has the IsNull() function.

  3. #3
    dvgef2 is offline Novice
    Windows 8 Access 2013
    Join Date
    Mar 2013
    Posts
    25
    Thanks RuralGuy, I'm laughing at your comments even though you are most likely serious. Null does not equal Null just sounds funny! That 'Null' character certainly does seem to work inconsistently. I have been forced to use '= Null' before and it seemed to work ok. I guess I should find those areas where it is working and fix it before problems arise.

    I thought I had a general understanding of Null but after reading your comments I realized that it was only a general understanding and certainly not a competent understanding. The compile error would never let me use 'Is Null' and would always push me to the '=' Null to get around compiling errors. The IsNull() function never worked for me but after researching it more, I realize that I was not using it right and VBA code seems to be picky about those things. Anyway, thanks again, it is working now...finally!
    Dave

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Excellent! Thanks for posting back with your success. Here's a good link to read: http://allenbrowne.com/casu-12.html
    Are you ready to use the Thread Tools at the top of the thread and mark this thread as Solved?

  5. #5
    dvgef2 is offline Novice
    Windows 8 Access 2013
    Join Date
    Mar 2013
    Posts
    25
    Thanks for the link, it has several other issues that I have experienced as well!

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Any time. Allen has a wealth of information in his site.

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

Similar Threads

  1. Command Button VBA Code
    By nyymattingly23 in forum Programming
    Replies: 13
    Last Post: 01-04-2013, 03:08 PM
  2. Replies: 3
    Last Post: 05-16-2012, 10:20 AM
  3. Command button code to clear form
    By windwardmi in forum Forms
    Replies: 15
    Last Post: 11-21-2010, 03:21 PM
  4. Form/report command button code
    By max3 in forum Forms
    Replies: 1
    Last Post: 08-26-2009, 02:18 AM
  5. Command button code
    By lfolger in forum Forms
    Replies: 3
    Last Post: 03-25-2008, 04:26 PM

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