How to open a form when database is opened based on a field value?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ryno Bower
    New Member
    • Nov 2010
    • 76

    How to open a form when database is opened based on a field value?

    Hey guys. I'm writing a program and want to do the following.

    I have a form for the company details called "companydetails ".
    So when I open the database I want the form to display first if the "companynam e" fiel is empty. After filling in the form and clicked on "create" then it must take me to another form called "employeeen try" so that the first employee can be created. After all is done the databse shoul close and reopen and then display the form "login" so that the employee can login to the system. The rest is all set up to happen afterwards.

    Thanks
    Ryno
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #2
    Hi Ryno

    I would create a blank form, call it "frm_StartU p". Then add an event procedure to the form's Load Event.
    It could look something like this:

    Code:
    Private Sub Form_Load()
      'Check if a company has been entered
      if DCount("*","tbl_Company")>0 then
        'There is at least 1 record in the table tbl_Company
        if Dcount("*","tbl_Employee")>0 then
          'There is at least 1 record in the table tbl_Employee
          'Close this form, and open login form
          Docmd.Close
          docmd.OpenForm "frm_Login"
        Else
          'There is a company but no employee registered
          'Close this form, and open Employee form
          Docmd.Close
          docmd.OpenForm "frm_Employee"
        End If
      Else
        'No company registered, close this form,and open company form
          Docmd.Close
          Docmd.OpenForm "frm_Company"
      End If
    End Sub
    In your Company form, you should have code attached to your Create button that will check that a valid entry is made, and if so open the employee form in teh same manner as described above.

    I hope this can get you started.

    EDIT: Of course you need to set the datebase to always start by opening the frm_Startup, this can be done under database startup settings.

    Comment

    • Ryno Bower
      New Member
      • Nov 2010
      • 76

      #3
      Thank you for the reply. Will try this and code around it if needed.

      Comment

      Working...