Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    Join Date
    May 2007
    Location
    Calgary, Canada
    Posts
    22

    Unanswered: Access Form Issue with docmd.close in ON OPEN event code!

    I need to have a form open, do something, and close without user input. But when I try to put a docmd.close at the end of either the ON OPEN or ON LOAD or ON ACTIVATE event code, I get a runtime error 2585 - This action can't be carried out while processing a form or report event. Does anyone have any ideas?

    Thanks!

  2. #2
    Join Date
    Aug 2006
    Posts
    559
    I have a question as to why you need a form to open, do something and then close WITHOUT user input?

    Second question, if you upload a zipped copy of your db and further explain which forms, what, etc... It'll help us to help you out. *It's easier to write code and figure if we have your exact forms/data names*

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    You can open a form as "acHidden" which maens the user never sees it...
    Then you can add what's called a "Timer" event to the form to close it (eg, after 1 second close the form).
    How good is that?!
    George
    Home | Blog

  4. #4
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    I'm curious as Grafixx01 is as to why you need to do this, but to each his own! I'd try placing a control on the form, setting focus on it in Form_Open or Form_Current, doing whatever you have to do, then closing it.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Alternatively if you give us more insight to what you are actually trying to achieve with this magic form then perhaps we can even suggest a better method
    George
    Home | Blog

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    if I remember correctly the close event cannot be triggered whilst the form os loading or opening.. you can CANCEL one or both of those events

    I Guess you would be better off opening the form as hidden, then killing it after what ever process you are opening it for finishes.... sounds a bit cockeyed.. but if it works for you......
    I'd rather be riding on the Tiger 800 or the Norton

  7. #7
    Join Date
    May 2007
    Location
    Calgary, Canada
    Posts
    22
    To make a long story short....

    We have an existing app that opens a form for user input. They want me to add the ability to select a button and have the form filled out the exact way x number of times.

    I know there are a million ways that are better to achieve the same result, but the easiest for me would be to have it close itself and move on...

    I am thinking about setting a hidden field on the main form and have that main form watch it and when I set that flag have it the main form close the form in question...

  8. #8
    Join Date
    Aug 2006
    Posts
    559
    Still doesn't make sense to me because wouldn't you just be creating duplicate records then? if you fill out a form x number of ways with the same data in that form? It'll create x number of records all containing the same data.

  9. #9
    Join Date
    May 2007
    Location
    Calgary, Canada
    Posts
    22
    Quote Originally Posted by Grafixx01
    Still doesn't make sense to me because wouldn't you just be creating duplicate records then? if you fill out a form x number of ways with the same data in that form? It'll create x number of records all containing the same data.
    Yes - but will print them.... that is what this form is doing, the VBA is populating multiple versions of the form one at a time then printing.

  10. #10
    Join Date
    Aug 2006
    Posts
    559
    Then my question is how are you going to know what "x" is if you require no user input.

    I can see a way to populate x number of records with the same data and print them out, however, you'd still have to tell how many records to do this with.

  11. #11
    Join Date
    May 2007
    Location
    Calgary, Canada
    Posts
    22
    Quote Originally Posted by Grafixx01
    Then my question is how are you going to know what "x" is if you require no user input.

    I can see a way to populate x number of records with the same data and print them out, however, you'd still have to tell how many records to do this with.
    The user imports a file so the program knows there are 25 records. It will fill in the form 25 times. If the user goes through the first couple then decides to just print the rest without seeing them. The program knows there are still 23 left to print. Opens the form 23 more times and prints. Just need to have the form close itself after each print.

  12. #12
    Join Date
    Aug 2006
    Posts
    559
    Will it ALWAYS be 25 records?

    If that's the case, **this is in my head now, so bear with me**, it sounds like you can make a query to get the difference of what has been entered versus the '25', like subtract what they enter from 25. Then have the query create records for the remainder, upon creating the records, print all records.


    I just saw a way to do this, well, not the printing all records, but the creating new records from a query. I'll see if I can find it again.

  13. #13
    Join Date
    Aug 2006
    Posts
    559
    C-COOP:

    Found this code for you to automatically add records and populate fields within the records with data that YOU specify. You'll have to manipulate it to have your field names and data you want in it.


    Code:
    ' Use the References dialog box
    ' to set up a reference to the
    ' Microsoft ActiveX Data Objects Library
    
    Sub Add_Record()
    Dim conn As ADODB.Connection
    Dim rst As ADODB.Recordset
    Dim strConn As String
    
    strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & CurrentProject.Path & _
    "\Northwind.mdb"
    
    Set rst = New ADODB.Recordset
    With rst
    .Open "Select * from Employees", _
    strConn, adOpenKeyset, adLockOptimistic
    
    ' Add a record and specify some field values
    .AddNew
    !LastName = "Marco"
    !FirstName = "Paulo"
    !City = "Boston"
    
    ' Retrieve the Employee ID for the current record
    Debug.Print !EmployeeId.Value
    
    ' Move to the first record
    .MoveFirst
    Debug.Print !EmployeeId.Value
    .Close
    End With
    
    Set rst = Nothing
    Set conn = Nothing
    
    End Sub
    Does that help any? I know there is some things in there that may not help, but I think it'll do the adding other records with specific data if you sub-in your fields and data.

    I think the only way you can do the form in the 'hidden' aspect would to logically do:

    OnClose of parent form, run query to see how many records contain the same data. If 'X' records IsNot =0, then run the "add record code above".

  14. #14
    Join Date
    May 2007
    Location
    Calgary, Canada
    Posts
    22
    Thanks for the reply,

    I already have the code that populates the form. I am looking for some code that will let me print and close a form without any user input.... So if I launch the form, it will open, print, then close on its own!

  15. #15
    Join Date
    May 2007
    Location
    Calgary, Canada
    Posts
    22
    Quote Originally Posted by georgev
    You can open a form as "acHidden" which maens the user never sees it...
    Then you can add what's called a "Timer" event to the form to close it (eg, after 1 second close the form).
    How good is that?!
    This could work, what do you mean by a timer event? Do you just mean the timer function?

Posting Permissions

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