Solved

How to stop the form from opening from a second user....

Posted on 2001-06-20
10
290 Views
Last Modified: 2008-02-26
Hello, stars,

Am trying to build an application that will be shared with about 4 or 5 users.  Want to allow them in this app to do other procedures.  I want to stop the option of successive users from using an Add Record form.  Here is what basically happens.  When they press a <Record Maintenance> button on the opening page, they are presented with all the current records in the database.  They can modify any field except the unique customized record number.  When they wish to add a new record to the table, they press a command button. A new form appears for input of this information.  While this form is open, I wish that no other user have the permission to open the form as the same customized number will be assigned.  That presents a conflict on closing one of the forms or loss of a number if the first user should cancel out the input.  How can I disable the command button if the Add button has a form open in another instance?

Thank you for stopping by and schooling me.

FlSteve
0
Comment
Question by:FlSteve
  • 2
  • 2
  • 2
  • +3
10 Comments
 
LVL 6

Expert Comment

by:PsychoDazey
Comment Utility
Function IsLoaded(ByVal strFormName As String) As Boolean
 ' Returns True if the specified form is open in Form view or Datasheet view.
   
    Const conObjStateClosed = 0
    Const conDesignView = 0
   
    If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then
        If Forms(strFormName).CurrentView <> conDesignView Then
            IsLoaded = True
            msgbox"you cannot open this form at this time", vbokonly
        exit function
        else
         'open your form
        End If
    End If
   
End Function
0
 
LVL 6

Expert Comment

by:PsychoDazey
Comment Utility
Sorry, put that code in the on click event of the command button.
0
 
LVL 7

Expert Comment

by:lmerrell
Comment Utility
You can use a table and add a record when the form is opened and the table is empty.  You could notify the user to try again later and Cancel the button click if the table has a record.  And then you would empty the table when exiting the form.

lmerrell
0
 
LVL 7

Expert Comment

by:lmerrell
Comment Utility
The IsLoaded function will only work for instances within the same session of the database, not for other users.
0
 
LVL 14

Accepted Solution

by:
mgrattan earned 100 total points
Comment Utility
You can create a table that stores only the NEXT unique record number that has not yet been assigned.  Each time a user clicks a button to create a new record, the table that contains your number can be updated to have that number incremented.  For example:

Private Sub btnNewRec_Click()
Dim db as DAO.Database, rs as DAO.Recordset
Set db = Currentdb
Set rs = db.OpenRecordset("tblUniqueRecNo", dbOpenDynaset)

rs.MoveFirst
rs.Edit
rs!RecNo = rs!RecNo + 1
rs.Update
rs.Close
Set rs = Nothing
Set db = Nothing

End Sub

Using this method, you won't have to worry about restricting users from having the form open simultaneously.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Expert Comment

by:dhinkle
Comment Utility
mgratten's solution is the one I use. I have a system where 5 of the users are keying new records all day long so allowing only one add at a time is not an option. I store the last used number in a table and when Add Record is clicked it grabs the number, adds 1 and writes it back so the next user has access to it. you would still have the issue of lost numbers though if someone cancelled. That is not an issue for my system fortunately but if it is for you you'll have to come up with a way to handle it. Possibly if a user cancelled you could write that number to an unused numbers table. Then when you were getting your next number you would check for an entry in that table first. If one existed you could use the number then delete it and if none existed get your number from the other table.
0
 

Author Comment

by:FlSteve
Comment Utility
OK, now that you have found my re-incarnation, you provided the code that I needed to get started, too.  Thanks, Mike.  You are exactly right about the IsLoaded function per instance.  Tried that and tried the disable of the command button.  But, in any successive instance, it did not apply.  This creating a table or inserting a record into a table makes good sense and I needed just a push on how to do this.  Thanks so much.  This is my first attempt with multiple users in which I need to lock a feature at one time.  

Also, the idea posed by another good fellow, of placing unused numbers in a suspense file is an excellent idea.  Have considered that concept and may just apply if the customer is willing to go with it.  Thank you for that suggestion.  

Thank all of you for stopping.   Some of us learned something and all had experiences to share.  

FlSteve  - Have a super day.

0
 
LVL 1

Expert Comment

by:dhinkle
Comment Utility
This is the code that I use to get the next number. May not be the best way but it works great. It lives in the OnClick event of the Add Record button

        Set db = CurrentDb()
        Set rst = db.OpenRecordset("tblMaxInsulationApplNo", dbOpenDynaset)
    'start the new record
        DoCmd.GoToRecord , , acNewRec
        cmdDeletePermit.Enabled = False
        cmdChangePermit.Enabled = False
        cmdPrintPermit.Enabled = False
        cmdMakePayment.Enabled = False

applno is the application number. I have to force a format on it but you would just need to set applno.value = rst!field.value

        ApplNo.Value = Format(Right(rst!MaxInsulationApplNo, 6) + 1, "000000")
 
write the used number back to the maxnumber table
       Do While Not rst.EOF
            rst.Edit
            rst![MaxInsulationApplNo] = ApplNo
            rst.Update
            rst.MoveNext
        Loop
        rst.Close
       
        Set rst = Nothing
        Set db = Nothing
0
 
LVL 14

Expert Comment

by:mgrattan
Comment Utility
Glad to help Steve!

Mike
0
 

Expert Comment

by:amp072397
Comment Utility
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now