Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    May 2002
    Location
    Jerusalem, Israel
    Posts
    187
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Identical VBA Code Doesn't Work in Another DB/Computer

    Hi,

    The purpose of the following code is to disable the three buttons if the Status field is empty so that the user cannot progress to the next step until the Status field (a combo box) is filled in:

    Private Sub Form_Current()
    If IsNull(Me.Status) Then
    Me.CloseOnly.Enabled = False
    Me.CloseNew.Enabled = False
    Me.CloseOpenAllActive.Enabled = False
    End If
    End Sub


    This code works fine on my computer, but the three buttons are ALWAYS disabled on a co-worker's computer, even after filling in the Status field. (He has a different database to me that serves a different purpose, but I want to reproduce the functionality from my database in his - the code is identical, so it should work the same way, right?) However, when it comes to this procedure, I can't figure out what the difference is between what he has and what I have.
    • In the properties, the buttons are set to Enable = Yes
    • I could not find any conflicting code anwhere in the project
    • In VBA I did Debug > Compile Documents and it did not find any errors
    • His VBA references are identical to mine
    • I tried compacting and repairing the front-end and the back-end
    We are both running Access 2010 on Windows 7.

    Thanks for any help you can provide.

    JoeK

  2. #2
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts
    I suspect the code isn't being executed. Put a break-point on the
    Code:
    If IsNull(Me.Status) Then
    line and see if it pops into the VBA editor. If it does, then look at Me.Status and see if it is null.
    Last edited by WendellB; 2011-05-18 at 08:12.
    Wendell

  3. #3
    2 Star Lounger
    Join Date
    May 2002
    Location
    Jerusalem, Israel
    Posts
    187
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by WendellB View Post
    I suspect the code isn't being executed. Put a break-point on the
    Code:
    If IsNull(Me.Status) Then
    line and see if it pops into the VBA editor. If it does, then look at Me.Status and see if it is null.
    Wendell,

    Thanks for your reply, but I'm not sure what you mean. I put a breakpoint on the line of code, closed VBA and then opened the form (which is blank, by default, when it loads). The VBA window opened and a yellow arrow was superimposed over the breakpoint circle.

    What does that tell me?

    Also, what are the possible reasons for code not executing? After reading a number of posts, I made sure that the DB is in a trusted location and macros are set to "trust everything".

    Thanks for your help,

    JoeK

  4. #4
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts
    You should be able to step through the code 1 line at a time and see what code is being executed, and whether Me.Status is really Null by doing that. If it isn't null, then there is something odd going on with that control - perhaps a default value has been set.
    Wendell

  5. #5
    2 Star Lounger
    Join Date
    Aug 2002
    Location
    Adelaide, South Australia, Australia
    Posts
    146
    Thanks
    5
    Thanked 5 Times in 5 Posts
    The following doesn't explain why it works on one computer, and I would normally expect it to produce an error, so it's probably just a transposition error when typing your post, but I would use exclamation marks instead of fullstops after me in the four lines referring to the field and buttons (because you're referring to added controls, rather than inbuilt properties or methods of the form):

    If IsNull(Me.Status) Then
    Me.CloseOnly.Enabled = False
    Me.CloseNew.Enabled = False
    Me.CloseOpenAllActive.Enabled = False

    should be

    If IsNull(Me!Status) Then
    Me!CloseOnly.Enabled = False
    Me!CloseNew.Enabled = False
    Me!CloseOpenAllActive.Enabled = False

    Apart from that, I'd do what Wendell has suggested, and look to see which line deviates from what you'd expect, so that you can focus your attention on that particular aspect of your code.

    Cheers

    Alison C
    Last edited by alifrog; 2011-05-18 at 23:14.

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
  •