[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


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

Posted on 2001-06-20
Medium Priority
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.

Question by:FlSteve
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +3

Expert Comment

ID: 6211788
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
         'open your form
        End If
    End If
End Function

Expert Comment

ID: 6211798
Sorry, put that code in the on click event of the command button.

Expert Comment

ID: 6211814
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.

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.


Expert Comment

ID: 6211837
The IsLoaded function will only work for instances within the same session of the database, not for other users.
LVL 14

Accepted Solution

mgrattan earned 400 total points
ID: 6212074
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!RecNo = rs!RecNo + 1
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.

Expert Comment

ID: 6214137
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.

Author Comment

ID: 6214243
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.


Expert Comment

ID: 6214268
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![MaxInsulationApplNo] = ApplNo
        Set rst = Nothing
        Set db = Nothing
LVL 14

Expert Comment

ID: 6215101
Glad to help Steve!


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

649 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