Results 1 to 10 of 10
  1. #1
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664

    Setting a breakpoint in code

    I am trying to walk through the code in the Sub updateButtons() in the attached db.

    I am very confused as to how to get there where to set the breakpoint.

    I could set it at the beginning of

    Sub updateButtons()

    That is the code that I wish to step through.



    But I have tried that and I never seem to get there. Obviously, Sub updateButtons() is called by something, but what?

    Where else can set the breakpoint?

    The db is attached as a zip file.

    Any help appreciated. thanks in advance.

    Respectfully,

    Lou Reed
    Attached Files Attached Files

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    select any line of code and press F9. (or click the vertical bar on the left)
    you cant set the break on SUB / FUNCTION lines , nor END {sub/func}

    you can add BEEP , then break on it.

  3. #3
    Micron is online now Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Quote Originally Posted by ranman256 View Post
    you cant set the break on SUB / FUNCTION lines , nor END {sub/func}
    You can in 2007.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Here is a good article by Chip Pearson on Debugging VBA
    http://www.cpearson.com/excel/debug.htm


    Looking at the code for the 2 subs "Sub updateButtons()" and where they are called form, I would suggest rewriting the sub and creating 1 sub.
    The only difference between the subs is the tables referenced and the forms the buttons are on.
    Attached Files Attached Files

  5. #5
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I think it would help if someon explained to me the executable steps in updateButtons(). I see that it looks a table and from there runs through a IF-THEN statement based on what it finds in the table.

    What is it looking for in the table? Why is it setting the buttons the ways it does when getting a parameter, and what are the choices.


    I have tried to see those two subforms in form mode, but to do that I must also know its parent main form. How do I do that? I tried just guessing what the parent or main form's name is from the subform's name and that failed to work.

    It would help a lot if I understood the mechanism of the updateButtons() program. Then I could right one for frmPersonnnel.


    If you notice in frmPersonnel there are a lot of buttons (about 11 or 12). My guess from looking at updateButtons subprogram in the two instances where it currently resides,
    shows that every button on the subform must be accounted for. That would be three in the current two subforms and 11 or 12 infrmPersonnel.

    So in order to write an updateButtons in the VBA code for frmPersonnel it is necessary to know what the two exiting updateButtons subprograms are doing.

    That is the reason for my question.

    It is not as simple as taking one of the current updateButtons subprograms and copying and pasting it into the VBA code for frmPersonnel.

    I did not write the original code for the two existing subform's VBA code. I believe they were originally macros and they were translated to VBA code. When it came to
    translating the macros attached the frmPersonnel all I was to also translate the same way the I did on the two subforms. The translator failed to perform a complete translation
    and here we are. No updateButtons for frmPersonnel and now I must put one in and I need some help.

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed

  6. #6
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I really need an answer to this question. It is critical in this project completed. Any help appreciated.

    Thanks in advance.

    Respectfully,

    Lou Reed

  7. #7
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    OK, looking closer, both DCount() functions are written incorrectly. Yes, Access evaluates the function, but the criteria should be written correctly.

    The value for PersonnelID should be concantated:
    Code:
     'this one does not concatenate the referenced value
     If DCount("*", "tblPropertyPass", "[PersonnelID] = [Forms]![frmPersonnel].[PersonnelID] AND [isActive] = true") = 0 Then
    
    'this one does concatenate the referenced value
      If DCount("*", "tblPropertyPass", "[PersonnelID] = " & [Forms]![frmPersonnel].[PersonnelID] & " AND [isActive] = true") = 0 Then


    Code:
    Public Sub updateButtons()
    1    If DCount("*", "tblPropertyPass", "[PersonnelID] = " & [Forms]![frmPersonnel].[PersonnelID] & " AND [isActive] = true") = 0 Then
    2        Me.btnClose.Enabled = False
    3        Me.btnEditProperty.Enabled = False
    4        Me.btnNew.Enabled = True
    5    Else
    6        Me.btnClose.Enabled = True
    7        Me.btnEditProperty.Enabled = True
    8        Me.btnNew.Enabled = False
    9    End If
    End Sub
    Disregarding the table names, this is what the sub does:
    Line #1: Count the records in a table where the PersonnelID equals the value on a form in a control named "PersonnelID". If the count equals 0, do the following:
    Line #2: disable the button named btnClose
    Line #3: disable the button named btnEditProperty '(btnEditTelework for the other sub)
    Line #4: enable the button named btnNew
    Line #5 Else '(DCount was not equal to 0)
    Line #6: enable the button named btnClose
    Line #7: enable the button named btnEditProperty '(btnEditTelework for the other sub)
    Line #8: disable the button named btnNew


    So the code sets the state of 3 buttons.
    In form "frmPersonnel", are there buttons named "btnClose", "btnNew" and (maybe) "btnEditPersonnel"?
    Last edited by ssanfu; 08-03-2017 at 03:31 PM. Reason: clarification

  8. #8
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Okay, why are those ampersands there?

    Again, please understand this was again a translated file. From MS Access 2010 macro to VBA translation. So I just took what the translator said. Also, I also used the exact same syntax in two other places in my code. They can be seen in the attached GIF files. Should these be changed also?

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed
    Attached Thumbnails Attached Thumbnails sfrmPropertyPass1.GIF   sfrm_telework1.GIF  

  9. #9
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by Lou_Reed View Post
    Okay, why are those ampersands there?
    Google "concatenate".
    Or open the VBA IDE, press F1, enter "concatenate" in the search box, click on the 2nd entry "How to: Use Numeric Criteria from a Control on a Form".

    Quote Originally Posted by Lou_Reed View Post
    Again, please understand this was again a translated file. From MS Access 2010 macro to VBA translation. So I just took what the translator said.
    As the programmer, you should really understand what the code is doing...... just sayin....


    Quote Originally Posted by Lou_Reed View Post
    Also, I also used the exact same syntax in two other places in my code. They can be seen in the attached GIF files. Should these be changed also?
    Its up to you. But knowing that concatenating is the proper method, what do you think???


    Paste the following sub into a module.
    Open "frmPersonnel", then execute the following code
    Look at the immediate window.
    Code:
    Public Sub TestConcat()
        Dim MyCriteria As String
    
        MyCriteria = "[PersonnelID] = [Forms]![frmPersonnel].[PersonnelID] AND [isActive] = true"
        Debug.Print MyCriteria
        MyCriteria = "[PersonnelID] = " & [Forms]![frmPersonnel].[PersonnelID] & " AND [isActive] = true"
        Debug.Print MyCriteria
    
    End Sub
    What is the difference??

  10. #10
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I did understand the code. I just did not know the criteria used in the two different selections on the IF- THEN statement. The code seemed to compile right after
    translation. So I thought it was okay. Then you said told me about concatenation and I used it. It even compiled then with no problem after I put in the concatenate statement.

    It worked. Again, I understood the macro and I thought that was good enough.

    It was not.

    This elaborate IF-THEN statement was put in by the translator from macro to VBA. Neither macro nor VBA was written by me. It even compiled which instigated my writing the post immediately above.
    It compiled in either case with or without the modifications you suggested.

    Microsoft is killing me with their arbitrary macro to BA code translation.

    Respectfully,

    Lou Reed

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

Similar Threads

  1. Setting Up A Macro to run VBA code
    By Lou_Reed in forum Access
    Replies: 32
    Last Post: 08-02-2017, 04:29 PM
  2. Disabled Breakpoint continues to stop code
    By Glenn_Suggs in forum Access
    Replies: 3
    Last Post: 08-15-2014, 04:32 PM
  3. Setting Code to Simple Numeric Age
    By wes9659 in forum Forms
    Replies: 6
    Last Post: 08-14-2014, 01:22 PM
  4. Setting Report Height In Code
    By ccordner in forum Reports
    Replies: 1
    Last Post: 12-07-2012, 10:26 PM
  5. Phantom Breakpoint
    By Paul H in forum Programming
    Replies: 1
    Last Post: 10-03-2012, 01:30 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