Results 1 to 8 of 8
  1. #1
    Join Date
    Dec 2005
    Posts
    7

    Unanswered: Wait for form to close before executing loop

    Access 2003

    Company sign in application. Each user signs in, watches a presentation, prints a badge. For a group, I have a form that asks how many are in group, show the pres one time, each user then fills in info on sign in, and a badge prints for each.

    Next dilemma, on the form I am asking the user how many are in group. Say they enter 3. I capture the number 3, they watch the presentation, then i perform a while loop that suppose to open the sign in form three times. But the loop executed too fast and it only lets one sign in. Here is my loop:

    Print_Badge:
    Do While varGroup > 0
    Do While IsLoaded("groupbadgeprint")
    Call Waitfor(3)
    Loop

    DoCmd.OpenForm "groupbadgeprint"
    varGroup = varGroup - 1

    Loop
    Exit Sub

    Here is the Waitfor function:

    Function Waitfor(Time As Integer)

    Dim DelayEnd As Double
    DelayEnd = DateAdd("s", Time, Now)
    While DateDiff("s", Now, DelayEnd) > 0
    Wend

    End Function

    The problem here is the program hangs in never, never land. What I need is something to say if "groupbadgeprint" is open, pause the loop.

    Any ideas?

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Set the modal property for your groupbadgeprint form to true. Modal effectively suspends code execution until the form is closed.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Dec 2005
    Posts
    7
    Thanks for the reply, but this did not work. Could it be where I am setting modal. I am setting in the Form_Load of "groupbadgeprint" and setting it like so:

    Me.Modal = true

  4. #4
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    do it in design mode. hard set the property to true.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  5. #5
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    (this is after a couple of beers, so it could be me rather than you) but it is not crystal clear to me why you want to mess around in the calling form.

    see if this fits:

    private sub myCallingFormWhatever()
    'earlier code...
    docmd.OpenForm "blahForm",,,,,acDialog
    'later code...
    end sub

    later code doesn't happen until blahForm closes

    you can loop in blahForm until the power fails, print a million badges, etc etc

    izy
    currently using SS 2008R2

  6. #6
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    THAT'S what I was looking for! I was recalling that post yesterday about the guy who's form kept opening modal and wouldn't execute code until it closed...
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  7. #7
    Join Date
    Dec 2005
    Posts
    7
    Thanks guys for your help, but I got around it a different way. Created a public variable to hold the number of badges to print used a different sub to handle the looping. The modal did help though.

    Thanks.

  8. #8
    Join Date
    Dec 2005
    Posts
    7
    I did some quick rework to see if I can get the loop to work using izyrider's suggestion. It was the "acDialog" that I was needing. I was just opening the form with a

    DoCmd.OpenForm "groupbadgeprint"

    After adding the acDialog works like a charm....

    I'll know next time.

    Thanks again.

Posting Permissions

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