Results 1 to 12 of 12

Thread: How could I?

  1. #1
    Join Date
    Apr 2003
    Location
    FL
    Posts
    50

    Unanswered: How could I?

    I have created an application in Access 2000. I have multiusers using this application. Like usual application, I have about 29 different forms.

    I want to know if one of the users has opened a perticular form. Meaning If any of the users is working on that form (In-use), I want to ristrict another user to open that form. Two user at the same time should not open that perticular form. I may display a message for the second user that "The Form is in use by another user" or something like that.

    Is there any way to check it?

    Please note that I want to do this with only one of the Forms.

    Anyone who could help me with this...

    Sandeep

  2. #2
    Join Date
    Jan 2003
    Location
    Aberdeen, Scotland, UK
    Posts
    168
    make a module with the following function:

    Function IsOpen(StrName As String, Optional intObjectType As Integer = acForm)
    IsOpen = (SysCmd(acSysCmdGetObjectState, intObjectType, StrName) <> 0)
    End Function

    Can't remember where I got the above function it just seems like part of the furniture now. If I should've thanked someone for it then.. thanks.

    on the code that opens the form (not the onopen event of the form)

    if isopen("NameOfForm") then
    msgbox"Form open by another user"
    exit sub
    end if
    J.

  3. #3
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    interesting....

    what if you have a server-based back-end and client front-ends?
    do you need the calling code AND the module AND the form on the back-end?

    izy

  4. #4
    Join Date
    Jan 2003
    Location
    Aberdeen, Scotland, UK
    Posts
    168
    Good question. I believe that the engine would consider each front end as a different form.

    I think you would have to use a different method.

    You could create a table called TblFormOpen and create a field called IsFormOpen (make it a yes/no).

    Then on the code that opens the form.

    set db.openrecordset("[tblformopen]")
    if rs![isformopen] then
    msgbox"Form in use"
    exit sub
    else
    rs.edit
    rs![isformopen] = true
    rs.update
    docmd.openform"WhateverItsCalled"
    end if
    rs.close

    and on the onclose of the form make it update the recordset to be isformopen = false.

    Not quite as pretty as the original method but it'd work i spose.


    You could also see if the table/query the form was bound to was open with the original method. But if more than one form was bound to it you'd have probs.

    John
    J.

  5. #5
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    Hmmm,

    i was trying to work up an answer when i saw your neat function.
    i just can't get how machine-A can see what machine-B is doing when they only have a dumb server between them

    given that most back-ends are access-dumb file servers, my guess is the solution has to be file based. my thoughts so far were:

    table on the server with "i am busy" field

    or

    .txt file on the server... the caller of the special form must first write-open the text file: error trapping rejects second+ attempts.

    it's a very interesting subject!

    izy

  6. #6
    Join Date
    Jan 2003
    Location
    Aberdeen, Scotland, UK
    Posts
    168
    The bit earlier ( my 2nd posting) does basically the same as creating a file. It stamps a table that all users are linked to.

    I'm not sure what would happen if (although unlikely) 2 users tries to open it at the same time.

  7. #7
    Join Date
    Apr 2003
    Location
    FL
    Posts
    50

    How could I?

    First of all I am greatly thankful to you John. I think the first option should work. I am also Thankful to izy as he came out with a thought that could be the case!! Finally BOTH of you gave me the solution for problems expected by each-other!! You both guys are great. Thanks a lot for your help and I do admire you knowledge. I think I need lot more experience to answer this kind of questions... I would try each option one-by-one and let's see which works the best...
    Sandeep

  8. #8
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    how about access' lock/unlock stuff - i guess mr. gates thought about two concurrent lock attempts!

    izy

  9. #9
    Join Date
    Jan 2003
    Location
    Aberdeen, Scotland, UK
    Posts
    168
    Your right. I remember seeing in my Developers Handbook (Which is unfortunately (and strangely) on my bathroom floor at home) a module for checking for locking (both pesimistic and opportunistic) and dealing with it.

    The way the code is at the minute it would prob. give a runtime error saying the records was locked by onther user.

    I'll have a look (at the Dev Handbook) when I get home. Unless you've got one Izy? I think it's chapter 8/9 ish.

  10. #10
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    no, i don't have the handbook.
    i have these little rolls of paper with perforations in them......


    izy

  11. #11
    Join Date
    Jan 2003
    Location
    Aberdeen, Scotland, UK
    Posts
    168
    In fact I just dug out another book:

    (This is a VERY crude example)

    Sub Something()
    On error goto ErrorBit
    set db.openrecordset("[tblformopen]")
    BackAgain:
    if rs![isformopen] then
    msgbox"Form in use"
    exit sub
    else
    rs.edit
    rs![isformopen] = true
    rs.update
    docmd.openform"WhateverItsCalled"
    end if
    rs.close

    ErrorBit:

    if err.number = 3260 then
    msgbox"Click here is a sec or two"
    goto BackAgain

    exit sub
    J.

  12. #12
    Join Date
    Jan 2003
    Location
    Aberdeen, Scotland, UK
    Posts
    168
    Originally posted by izyrider
    no, i don't have the handbook.
    i have these little rolls of paper with perforations in them......


    izy
    I read that about 4 times before I got it. I think it must be time to go home.

    j.
    J.

Posting Permissions

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