Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2004
    Location
    NY
    Posts
    113

    Unanswered: Form Load question

    Hi,

    I have a counter that computes in the following format (mmyyseq#) the seq# resets back to 000 and the beginning of each month. This is working fine, however on the form load I noticed that it is doubling each time.

    When I step through the code, I notice that the form loads once and then again. I have a subform but I don't think this is causing the problem. Any help would be appreciated. Thanks

    Code:
        Dim s As String
        Dim mNum As Integer
    
        Seq_Number = NewSeqNumber(Seq_Number.Value)
    
    If Me.Dirty Then Me.Dirty = False
       mNum = Me.sfrmQuestionsAnswers.Form.Recordset.RecordCount
       
       'Populate tblAnswer
       s = "INSERT INTO tblAnswers ( QuestionID, Seq_Number  )" _
          & " SELECT QuestionID, " & Me.Seq_Number _
          & " FROM tblQuestions " _
          & " WHERE tblQuestions.IsActive=True;"
          
       CurrentDb.Execute s
        
       Me.sfrmQuestionsAnswers.Requery
    ======================
    Levent
    Access 3

  2. #2
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    only twice is quite good - with a little effort you could achieve much worse.

    you don't provide complete code so i can't provide a complete answer.

    my preference is to dissociate the _Load event from code that should run once when the form loads. i use the timer (designtime TimerInterval = 1) and zero code in the _Load event apart from insisting on the timerinterval:
    me.timerinterval = 1
    ...the timer does NOT tick until the _Load event (with its subforms ...possibly the root cause of your issue is _Load interaction between various forms) has completed.

    then in _Timer
    'switch off the run-once timer
    me.timerinterval = 0
    'do my run-once "_Load" stuff
    blah
    ...this _Timer event kicks off 1 millisecond after the _Load event has fully completed.

    the alternative approach is boring and involves tracking down what is triggering which event at _Load (_Open, _Current etc etc etc). breakpoint the first line of _Load and F8 it through all the way to the end to see what is happening if this is the route you prefer.

    izy
    currently using SS 2008R2

  3. #3
    Join Date
    Aug 2004
    Location
    NY
    Posts
    113
    This for a questionaire form and I am trying to preload the questions. The counter is working fine. When I worked on the code and tested it in a command button it incremented correctly.

    Why would the form load do it twice? That is what I can't understand.
    ======================
    Levent
    Access 3

Posting Permissions

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