Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Jan 2002
    Location
    Brugge, Belgium
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    something strange (Access 2007)

    This code belongs to the onfocus event of the control txtartnr on a form "subformOrders".
    When this form together with the "order" form is open, and there is already a articlenr in the control txtartnr, then a first message must appear with the text 'onfocus', and at the end of the code the two other messages. Its for purpose of testing.
    What happens is that only the first message appear, but the two other messages not.
    What is wrong with this code.
    The goal of the code is to make it possible to make the neccesary corrections after the articlenr of the orderitem is changed.
    The data of the original orderitem has to be saved in variables as VorigArttnr etc. Is the onfocus event therefore the wright place ?


    Private Sub txtArtnr_GotFocus()

    On Error GoTo ArtnrFocus_Fout
    veranderd = False

    If IsNull(Me!txtArtnr) Then
    leeg = True
    VorigArtikel = ""
    VorigeQty = 0
    Else
    MsgBox ("onfocus")
    VorigArtikel = Me!txtArtnr
    VorigeQty = Me![Bestelde Hoeveelheid]
    Vorigeprijs = Me!Eenheidsprijs
    VorigeBtw = Me!BTW
    VorigeBtwNr = Me!BtwNr
    Vorigekorting = Me!Korting
    Vorigevoorraad = Me!Voorraad
    Vorigelevering = Me!Geleverd
    VorigeNalevering = Me!Nalev
    Oudevoorraad = Me!Voorraad + Me!Geleverd

    leeg = False
    MsgBox ("vorigartikel was " & VorigArtikel)
    MsgBox ("vorigbtw was " & CStr(VorigeBtw))

    End If

    ArtnrFocus_Afsluiten:
    On Error GoTo 0
    Exit Sub


    ArtnrFocus_Fout:
    Mededeling = foutbericht("Bij focus txtArtnr", "subfrmOrders", Err)
    Resume ArtnrFocus_Afsluiten

    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: something strange (Access 2007)

    1) If the line MsgBox ("onfocus") is executed, but MsgBox ("vorigartikel was " & VorigArtikel) is *not* executed, an error must have occurred in between. What does the function foutbericht do? Does it display a message? If so, you should see the error message.

    2) Have the variables VorigArtikel etc. been declared at the top of the form module, or in a standard module?

  3. #3
    2 Star Lounger
    Join Date
    Jan 2002
    Location
    Brugge, Belgium
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: something strange (Access 2007)

    Dear Hans;

    Indeed you're wright! I misspelled the name of one of the fields : the fieldname "Bestelde Hoeveelheid" must be "BesteldeHoeveelheid", thus without a space between.
    What a pity that we don't get a kind of message in such a case, to help us find out what's wrong. There 's just no error message at all !!!
    On the other side i must confess that my knowledge about working with the debugging features in the VBA editor, is'nt so good.
    I often tried , when a sub or function is displayed in de VBA editor ,putting the cursor in this sub or function, activating the menuItem 'run function/subroutine", but nothing happens.
    I'm sure i'm doing something wrong, but don't know what, nor how to get it done to start the debugging for this subor function, so that after the start a step by step procedure can be followed.
    Do you know a good site on the internet where all the stuff about debugging in MS Access + VBA, is well explained.
    Also, in the VBA -editor of VB.NET we have the possibility to add linenumbers on each line of the code. I wonder if this is possible in the VBA editor of MS Access and if so, what to do to get them?

    By all means , thank you very much for the help you gave me!

    Regards

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: something strange (Access 2007)

    A procedure such as Private Sub txtArtnr_GotFocus() is an event procedure, i.e. it is run automatically if a specific event occurs, in this example the On Got Focus event of the txtArtnr text box. You cannot run such a procedure by itself - in most cases the code would make no sense if run by itself, outside of the context of the event.

    You can, however, put a breakpoint in the code so that execution will pause. To set a breakpoint on a line, click in the gray margin to the left of the line, or click in the line and press F9. The same methods can be used later on to remove the breakpoint.

    When Access runs the code, it will pause at the line with the breakpoint. The current line will be highlighted.
    You can execute the code step by step by pressing F8.
    Hovering the mouse pointer over a variable will often show its value.
    Press F5 to resume uninterrupted code execution.
    Note: not all code can be run in single step mode. Access will warn you if this is the case.

    You'll find more info in
    Debugging VBA
    Debugging VBA Code in Access 2003/XP/2000/97 (a 12-step tutorial, don't forget to click Next >>)

    There's a handy free add-in for the Visual Basic Editor: MZ-Tools 3.0. One of its features is adding/removing line numbers.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •