++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
VBA Code of the data base 'OrderBase-V190211.mdb'
12.02.2019 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++

========================================================
Code of the form 'frmHelp'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmHelp"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database
Option Explicit

Private Sub cmdClose_Click()
'--------------------------------------------------------------
DoCmd.Close
End Sub

Private Sub Form_Open(Cancel As Integer)
'--------------------------------------------------------------
' The text box txtHelpText is filled with a text from the table tblHelp

' DLookup("help_text", "tblHelp", "help_name='" & CStr(OpenArgs) & "'") means:

' Get the contents of the column "help_text" from the table "tblHelp", where
' the contents of the column "help_name" is equal to the form opening argument
' ("OpenArgs"). This OpenArgs is set by the OpenForm command - for example like this:
' DoCmd.OpenForm "frmHelp", , , , , , "customers" (from the module frmCustomers) or this:
' DoCmd.OpenForm "frmHelp", , , , , , "employees" (from the module frmEmployees)

' "Nz" sets the result of DlookUp to "" (an empty string),
' if the selected column in tblHelp is empty.

txtHelpText = Nz(DLookup("help_text", "tblHelp", "help_name='" & CStr(OpenArgs) & "'"), "")

End Sub

========================================================
Code of the form 'frmHRplanning1'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmHRplanning1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database
Option Explicit

' ===============================================================
' Sorry ...
' ... the comments are not yet completely translated into English
' ===============================================================

Public Sub public_personalplanung1()
'--------------------------------------------------------------
Call Parent.public_pp_mitarbeiter
End Sub

Public Sub public_lstOrders_AfterUpdate()
'--------------------------------------------------------------
' Damit die ...liste_AfterUpdate()-Prozedur von "auen" - also von
' anderen Formularen aus - aufgerufen werden kann, muss eine entspr.
' "Public-Version" definiert werden.

Call lstOrders_AfterUpdate
End Sub

Private Sub cboOrderStatus_GotFocus()
'--------------------------------------------------------------
' Sicherheitsmanahme: Falls der Inhalt des Kombinationsfedles in einem ANDREREN Formular
'                      gendert wurde, muss es hier aktualisiert werden.
cboOrderStatus.Requery

End Sub

Private Sub lstOrders_AfterUpdate()
'--------------------------------------------------------------
'Die Daten des in der Liste angeclickten Datensatzes anzeigen

If Not IsNull(lstOrders) Then Me.Recordset.FindFirst "ord_id=" & Me!lstOrders

Parent!txtFrom = ""
Parent!txtTo = ""
Parent!txtRemark = ""

End Sub

Private Sub Form_Open(Cancel As Integer)
'--------------------------------------------------------------
' Anzeige des ersten Datensatzes in der Liste

Me!lstOrders.SetFocus
If Nz(lstOrders.ListCount) > 0 Then   ' erste Zeile anzeigen
   Me!lstOrders = Me!lstOrders.ItemData(0)
   Call lstOrders_AfterUpdate
End If

' You can use the tab-key to move the input marker from box to box.
' The following command defines, what should happen, if you press
' the tab-key in the last box on the form.
' "1" means: "Jump back to the first box on the form!"

Me.Cycle = 1

End Sub

Private Sub txtName_DblClick(Cancel As Integer)
'--------------------------------------------------------------
' Open the form frmCustomers and display the data of that
' customer there, that was double clicked here!
' (identified by its primary key "cus_id")

' "Me!cus_id" is the argument, that appears as "OpenArgs" in
' Form_Open in frmCustomers!

DoCmd.OpenForm "frmCustomers", , , , , , Me!cus_id

End Sub

========================================================
Code of the form 'frmHRplanning2'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmHRplanning2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database
Option Explicit

' ===============================================================
' Sorry ...
' ... the comments are not yet completely translated into English
' ===============================================================

Public Sub public_personalplanung2()
'--------------------------------------------------------------
Call Parent.public_pp_auftraege
End Sub

Public Sub public_lstEmployees_AfterUpdate()
'--------------------------------------------------------------
' Damit die ...liste_AfterUpdate()-Prozedur von "auen" - also von
' anderen Formularen aus - aufgerufen werden kann, muss eine entspr.
' "Public-Version" definiert werden.

Call lstEmployees_AfterUpdate
End Sub

Private Sub lstEmployees_AfterUpdate()
'--------------------------------------------------------------
'Die Daten des in der Liste angeclickten Datensatzes anzeigen

If Not IsNull(lstEmployees) Then Me.Recordset.FindFirst "emp_id=" & Me!lstEmployees

Parent!txtFrom = ""
Parent!txtTo = ""
Parent!txtRemark = ""

End Sub

Private Sub Form_Open(Cancel As Integer)
'--------------------------------------------------------------
' Anzeige des ersten Datensatzes in der Liste

Me!lstEmployees.SetFocus
If Nz(lstEmployees.ListCount) > 0 Then   ' erste Zeile anzeigen
   Me!lstEmployees = Me!lstEmployees.ItemData(0)
   Call lstEmployees_AfterUpdate
End If

' You can use the tab-key to move the input marker from box to box.
' The following command defines, what should happen, if you press
' the tab-key in the last box on the form.
' "1" means: "Jump back to the first box on the form!"

Me.Cycle = 1

End Sub

Private Sub txtName_DblClick(Cancel As Integer)
'--------------------------------------------------------------
' Open the form frmEmployees and display the data of that
' employee there, that was double clicked here!
' (identified by its primary key)

' "Me!emp_id" is the argument, that appears as "OpenArgs" in
' Form_Open in frmEmployees!

DoCmd.OpenForm "frmEmployees", , , , , , Me!emp_id

End Sub

========================================================
Code of the form 'frmHRplanning2_sfmOrders'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmHRplanning2_sfmOrders"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Option Compare Database

' ===============================================================
' Sorry ...
' ... the comments are not yet completely translated into English
' ===============================================================

Private Sub cmdDelete_Click()
'--------------------------------------------------------------
Dim lngAnswer As Long
Dim strMsgtext As String
Dim strSQL As String

' Safety question

strMsgtext = "Do you really want to delete this assignment?"
lngAnswer = MsgBox(strMsgtext, vbYesNo + vbDefaultButton2)

' Delete the assignment

If lngAnswer = vbYes Then
   strSQL = "DELETE FROM tblEmp_Ord WHERE ord_id_f=" & _
              CStr(Me!ord_id) & _
              " AND emp_id_f=" & _
              CStr(Parent!lstEmployees)
   'MsgBox strSQL
   CurrentDb.Execute strSQL
   Forms!frmHRplanning!frmHRplanning1.Requery
   Forms!frmHRplanning!frmHRplanning2.Requery
End If

End Sub

Private Sub Form_Open(Cancel As Integer)

' You can use the tab-key to move the input marker from box to box.
' The following command defines, what should happen, if you press
' the tab-key in the last box on the form.
' "1" means: "Jump back to the first box on the form!"

Me.Cycle = 1

End Sub

Private Sub txtDescription_Click()
'--------------------------------------------------------------
' Der Click auf die Auftragsbeschreibung soll diesen Auftrag im Unterformular "frmHRplanning1" auswhlen
' und dort aber auch gleich bewirken, dass die zu diesem Auftrag gehrigen Mitarbeiter angezeigt werden.
' Zu diesem Zweck muss ein Click in die Auftragsliste simuliert werden - und zwar durch den Aufruf der
' Prozedur auftragsliste_AfterUpdate.
' Das ist aber nicht so ohne weiteres mglich. Es muss zunchst eine Public Prozedur im bergeordneten
' Formular aufgerufen werden, die wiederum eine Public Prozedur in ihrem bergeordenten Formular aufruft.
' Das ist dann das Startformular "frmHRplanning". Die Prozedur dort kann dann letztendlich die Prozedur
' public_auftragsliste_AfterUpdate im Unterformular "frmHRplanning1" aufrufen.
' Dass ist ein ziemlicher Irrweg - aber anders habe ich es nicht hingekriegt ...

Forms!frmHRplanning!frmHRplanning1!lstOrders = Me!ord_id
Forms!frmHRplanning!frmHRplanning1!lstOrders.SetFocus
Call Parent.public_personalplanung2

' Anzeige der Daten, damit sie mittels "Speichern" gendert werden knnen

Parent.Parent!txtFrom = Me!txtFrom
Parent.Parent!txtTo = Me!txtTo
Parent.Parent!txtRemark = Me!txtRemark

End Sub

Private Sub txtDescription_DblClick(Cancel As Integer)
'--------------------------------------------------------------
' Open the form frmOrderProcessing and display the data of that
' order there, that was double clicked here!
' (identified by its primary key "ord_id")

' "Me!ord_id" is the argument, that appears as "OpenArgs" in
' Form_Open in frmOrderProcessing!

DoCmd.OpenForm "frmOrderProcessing", , , , , , Me!ord_id
End Sub

========================================================
Code of the form 'frmEmployees'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmEmployees"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Option Compare Database

' ATTENTION!!
'=================================================================
' In this final version of the form some more code has been added
' in addition to the code, that was automatically generated by the
' wizards. It makes the application more professional.
' Please read the explanations in the code carefully!
'=================================================================

Private Sub cmdPrintAll_Click()
'--------------------------------------------------------------
' Print the data of all employees.
' The printing is not executed immediately. First a preview is shown.

DoCmd.OpenReport "rptEmployee", acViewPreview
End Sub

Private Sub cmdPrintOne_Click()
'--------------------------------------------------------------
' Print the data of the employee, that is selected in the list.
' (This is defined by its primary key "emp_id"!)

' Has the user selected an employee from the list?

If IsNull(lstEmployees) Then
   MsgBox "Please select an employee from the list!"
   Exit Sub
End If

' "Me" means the form itself ("Hi - it's me!")
' The printing is not executed immediately. First a preview is shown.

DoCmd.OpenReport "rptEmployee", acViewPreview, , "emp_id=" & CStr(Me!emp_id)

End Sub

Private Sub cmdHelp_Click()
'--------------------------------------------------------------
' Show the form with the help information
' "employees" is the argument, that appears as "OpenArgs" in
' Form_Open in frmHelp! It is used to say the form frmHelp, which
' help information shall be shown.

DoCmd.OpenForm "frmHelp", , , , , , "employees"

End Sub

Private Sub cmdDelete_Click()
'--------------------------------------------------------------
' Delete one employee

' Definition of variables

Dim lngAnswer As Long      ' Type "Long integer"
Dim strMsgtext As String   ' Type "String"

' Has the user selected one employee in the list?

If IsNull(lstEmployees) Then
   MsgBox "Please select an employee from the list!"
   lstEmployees.SetFocus
   Exit Sub
End If

' Safety question
' Attention: By default, the second button ("No") of the corresponding
' message window is activated. That means: If the user only presses
' the "Enter" key, the delete command is NOT executed!

strMsgtext = "Do you really want to delete the employee " & Me!txtFirstName & " " & _
             Me!txtLastName & "?"
lngAnswer = MsgBox(strMsgtext, vbYesNo + vbDefaultButton2)

' Execute the delete
' ....................
' Before the entity can be deleted from the table , all references to it
' in other tables must be deleted.

' In this case the entries in tblEmp_Ord must be deleted, before the
' employee itself can be deleted.

' ACHTUNG: Das automatische Lschen des Verweises auf den zu lschenden
'          Mitarbeiter in tblEmp_Ord ist nicht ganz unproblematisch!
'          Damit geht die Information verloren, dass ein bestimmter
'          Mitarbeiter - den es JETZT in der Firma nicht mehr gibt -
'          irgendwann in der VERGANGENHEIT einmal bestimmte Auftrge
'          bearbeitet hat!
'          Es knnte ebenso gut sein, dass der zu lschende Mitarbeiter
'          fr in der ZUKUNFT zu erledigende Auftrge eingeplant war.
'          Nach der Lschung des Mitarbeiters ist dann u.U. fr
'          bestimmte Auftrge NIEMAND mehr eingeplant!
'
' Wenn man verhindern will, dass in der Vergangeheit oder fr die Zukunft
' eingeplante Mitarbeiter gelscht werden, muss man vorgehen wie im
' Modul Form_frmMaterials bei der Lschung von Materialarten oder
' wie im Modul Form_frmCustomers bei der Lschung von Kunden!
'    (In diesen beiden Modulen werden zwei unterschiedliche
'    Lsungsvarianten demonstriert!)
' Das heit: Wenn es noch Fremdschlsseleintrge in tblEmp_Ord gibt,
' kann der betreffende Mitarbeiter nicht gelscht werden.

If lngAnswer = vbYes Then   ' If the user has answered the safety question with "Yes" ...

   ' First: Delete any reference to the entity to be deleted!
   CurrentDb.Execute "DELETE FROM tblEmp_Ord WHERE emp_id_f=" & CStr(Me!emp_id)
   ' Then: Delete the entity itself!
   CurrentDb.Execute "DELETE FROM tblEmployee WHERE emp_id=" & CStr(Me!emp_id)
   
   lstEmployees.Requery     ' Refresh the list (=the deleted entity disappears)
   Requery                  ' Refresh the form
   lstEmployees.SetFocus
   
   ' Activate the first line of the list ("ItemData(0)") and
   ' show the data of that entity
   
   If Nz(lstEmployees.ListCount) > 0 Then
      Me!lstEmployees = Me!lstEmployees.ItemData(0)
      Call lstEmployees_AfterUpdate
   End If

End If

End Sub

Private Sub cmdNew_Click()
'--------------------------------------------------------------
' Add a new employee

' No line shall be selected in the list

lstEmployees = Null

' Create a new data record

DoCmd.GoToRecord , , acNewRec

' The user can immediately start typing, because the text marker
' is placed in the text box txtLastName

txtLastName.SetFocus

' If the user wants to enter a new entity, it makes no sense to
' start another action immediately after clicking on "new".
' Therefore all the other buttons are disabled.
' They are enabled again after the user has clicked "save"!

cmdNew.Enabled = False
cmdDelete.Enabled = False
lstEmployees.Enabled = False
cmdPrintOne.Enabled = False
cmdPrintAll.Enabled = False

End Sub

Private Sub cmdClose_Click()
'--------------------------------------------------------------
' Close the form
DoCmd.Close
End Sub

Private Sub cmdSave_Click()
'--------------------------------------------------------------
' Save the data to the data base

Dim lngEmpId As Long

' Has the user entered at least a last name?

If Nz(txtLastName) = "" Then
   MsgBox "Please enter a last name!"
   txtLastName.SetFocus
   Exit Sub
End If

' Save command

DoCmd.RunCommand (acCmdSaveRecord)

' The primary key of the saved entity is stored in a variable.
' This is used to activate the saved entity in the list.
' Otherwise after "Requery" the first entity of the list
' is activated. This would confuse the user, because the
' data displayed in the form are not the data of the entity
' that is selected in the list.

lngEmpId = Me!emp_id

' Refresh the list
' (the FIRST entry of the list is activated now!)

lstEmployees.Enabled = True
lstEmployees.Requery

' Activate the just saved entity in the list again ...

lstEmployees.SetFocus
lstEmployees = lngEmpId

' ... and show its data in the form.

Call lstEmployees_AfterUpdate

End Sub

Private Sub cmdStartform_Click()
'--------------------------------------------------------------
DoCmd.OpenForm "frmStart"
End Sub

Private Sub Form_Open(Cancel As Integer)
'--------------------------------------------------------------
' This form may be opend
'  -  either directly by a click in the start form or on the ribbon
'  -  or "indirectly" by a double click from "another" form.

' In that case, the entity, that was double clicked in the other form
' shall be displayed here - instead of the first entry from the list,
' which is displayed, if the form is simply opend from the start form or
' from the ribbon.

' The primary key of the double clicked entity is sent from the other
' form to this form via a variable called "OpenArgs" (=opening arguments).
' Which form that was, doesn't matter. The code works for any other form,
' that sends an "OpenArgs".

 ' To check this, have a look to the procedure
 ' txtName_DblClick in the form frmHRplanning2
 
Me!lstEmployees.SetFocus

If IsNull(OpenArgs) Then   ' The form was opend from the start form
                           ' or from the ribbon because OpenArgs is empty

   ' Activate the first line of the list and show the data of that
   ' entity in the form.
   
   If Nz(lstEmployees.ListCount) > 0 Then
      Me!lstEmployees = Me!lstEmployees.ItemData(0)
      Call lstEmployees_AfterUpdate
   End If

Else                       ' The form was opend by a double click
                           ' in another form because OpenArgs is NOT empty

   ' Activate that line of the list, that contains the entity,
   ' that was double clicked in the other form.
   ' (The entity to be activated is identified by its primary key,
   '  which is sent via OpenArgs!)
   
   Me!lstEmployees = OpenArgs
   Call lstEmployees_AfterUpdate
   
End If

' Enable all controls

cmdNew.Enabled = True
cmdSave.Enabled = True
cmdDelete.Enabled = True
lstEmployees.Enabled = True
cmdPrintOne.Enabled = True
cmdPrintAll.Enabled = True

' You can use the tab-key to move the input marker from box to box.
' The following command defines, what should happen, if you press
' the tab-key in the last box on the form.
' "1" means: "Jump back to the first box on the form!"

Me.Cycle = 1

End Sub

Private Sub lstEmployees_AfterUpdate()
'--------------------------------------------------------------
' Show the data of that entity, that was selected in the list, in the form

' The following line of code was a bit "compressed" in comparison to
' the code, that was automatically generated by the list box wizard.
' (see step 7)

' The following line of code means:
' If the list lstEmployees is not emtpy ("Not IsNull"), then ...
' ... search within the recordset (=the data source) of the current form ("Me")
' for the first value of "emp_id" (=the primary key in tblEmployee) that is equal
' to that one, that is selceted in the list box lstEmployees ("Me!lstEmployees")
' and display its data in the text boxes of the form

If Not IsNull(lstEmployees) Then Me.Recordset.FindFirst "emp_id=" & CStr(Me!lstEmployees)

' Enable the buttons, which may have been disabled before

cmdDelete.Enabled = True
cmdNew.Enabled = True
cmdPrintOne.Enabled = True
cmdPrintAll.Enabled = True

End Sub

Private Sub txtLastName_BeforeUpdate(Cancel As Integer)
'--------------------------------------------------------------
' The following code is very short, but needs a lot of explanation.
' Well - let's start:

' The storage of data in the data base may not only be executed with
' the command "DoCmd.RunCommand (acCmdSaveRecord)" which you know
' from the procedure cmdSave_Click. This is only the "explicit" method,
' which is executed by the user, who clicks on the "save" button.

' There is also an "implicit" storage method. It is executed, when
' you have entered data into a table (using the text boxes in a form)
' and then switch to another data record (by clicking into the list box).
' Access then assumes, that you are ready with editing the data
' and stores them.
' BUT: If the user has not yet entered all the necessary data,
'      this implicit storage must be prohibitet!
' This is done by this procedure.
' It is executed automatically by Access "before update", that means,
' before the storage (may be explicit / may be implicit!!) is executed.
' You can prohibit the execution of the storage by setting the argument
' "Cancel" to "True".

' Exactly that is done with the following code: If the user hasn't entered a
' last name (=necessary data!), the storage is prohibited!
' That's all.

If Nz(Me!txtLastName, "") = "" Then
   MsgBox "Please enter a name or press the Esc-key!"
   Cancel = True
End If

End Sub

========================================================
Code of the form 'frmCustomers2'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmCustomers2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Option Compare Database

' ATTENTION!!
'=================================================================
' In this final version of the form some more code has been added
' in addition to the code, that was automatically generated by the
' wizards. It makes the application more professional.
' Please read the explanations in the code carefully!
'=================================================================

Private Sub cmdPrintAll_Click()
'--------------------------------------------------------------
' Print the data of all employees.
' The printing is not executed immediately. First a preview is shown.

DoCmd.OpenReport "rptCustomer", acViewPreview
End Sub

Private Sub cmdPrintOne_Click()
'--------------------------------------------------------------
' Print the data of the customer, that is selected in the list.
' (This is defined by its primary key "cus_id"!)

' Has the user selected a customer from the list?

If IsNull(lstCustomers) Then
   MsgBox "Please select a customer from the list!"
   Exit Sub
End If

' "Me" means the form itself ("Hi - it's me!")
' The printing is not executed immediately. First a preview is shown.

DoCmd.OpenReport "rptCustomer", acViewPreview, , "cus_id=" & Me!cus_id

End Sub

Private Sub cmdHelp_Click()
'--------------------------------------------------------------
' Show the form with the help information
' "customers" is the argument, that appears as "OpenArgs" in
' Form_Open in frmHelp! It is used to say the form frmHelp, which
' help information shall be shown.

DoCmd.OpenForm "frmHelp", , , , , , "customers"

End Sub

Private Sub cmdDelete_Click()
'--------------------------------------------------------------
' Delete one customer

' Definition of variables

Dim lngAnswer As Long     ' Type "Long integer"
Dim strMsgtext As String  ' Type "String"

' Has the user selected one customer in the list?

If IsNull(lstCustomers) Then
   MsgBox "Please select a customer in the list!"
   lstCustomers.SetFocus
   Exit Sub
End If

' The following code demonstrates one possibility to find out,
' if there are references to the entity to be deleted in other tables.

' Attention: The code in cmdDelete_Click in module frmMaterials demonstrates
'            another possibility to find out, if there are references to
'            the entity to be deleted in other tables!

' If there are still orders from the customer, that shall be deleted,
' it is not possible to delete him, because otherwise, there would be
' foreign keys cus_id_f in tblOrder which do not exist in the
' primary key column cus_id of the table tblCustomer.
' (-> violation of the referential integrity!)

' DCount("ord_id", "tblOrder", "cus_id_f=" & CStr(Me!cus_id)) means:
' Count the number of entries in the column "ord_id" of the table
' "tblOrder" for which the value in column "cus_id_f" is equal to
' the primary key of the customer displayed in this form (="Me!cus_id")
' = "How many orders are there of the current customer?"


If DCount("ord_id", "tblOrder", "cus_id_f=" & CStr(Me!cus_id)) > 0 Then
   MsgBox "The customer can not be deleted. There are still orders of him!"
   Exit Sub
End If

' Safety question
' Attention: By default, the second button ("No") of the corresponding
' message window is activated. That means: If the user only presses
' the "Enter" key, the delete command is NOT executed!

strMsgtext = "Do you really want to delete the customer " & Me!txtFirstName & " " & Me!txtLastName & "?"
lngAnswer = MsgBox(strMsgtext, vbYesNo + vbDefaultButton2)

' Execute the delete
' ....................
' Before the entity can be deleted from the table , all references to it
' in other tables must be deleted.

' In this case the entries in tblContact must be deleted, before the
' customer itself can be deleted.

If lngAnswer = vbYes Then  ' If the user has answered the safety question with "Yes" ...

   ' Delete the contacts of the customer and then ...
   CurrentDb.Execute "DELETE FROM tblContact WHERE cus_id_f=" & CStr(Me!cus_id)
   ' ... delete the customer itself
   CurrentDb.Execute "DELETE FROM tblCustomer WHERE cus_id=" & CStr(Me!cus_id)
   lstCustomers.Requery   ' Refresh the list (=the deleted entity disappears)
   Requery                ' Refresh the form
   lstCustomers.SetFocus
   
   ' Activate the first line of the list ("ItemData(0)") and
   ' show the data of that entity
   
   If Nz(lstCustomers.ListCount) > 0 Then
      Me!lstCustomers = Me!lstCustomers.ItemData(0)
      Call lstCustomers_AfterUpdate
   End If

End If

End Sub

Private Sub cmdNew_Click()
'--------------------------------------------------------------
' Add a new customer

' No line shall be selected in the list

lstCustomers = Null

' Create a new data record

DoCmd.GoToRecord , , acNewRec

' The user can immediately start typing, because the text marker
' is placed in the text box txtLastName

txtLastName.SetFocus

' If the user wants to enter a new entity, it makes no sense to
' start another action immediately after clicking on "new".
' Therefore all the other buttons are disabled.
' They are enabled again after the user has clicked "save"!

cmdNew.Enabled = False
cmdDelete.Enabled = False
lstCustomers.Enabled = False

End Sub

Private Sub cmdClose_Click()
'--------------------------------------------------------------
' Close the form

DoCmd.Close

End Sub

Private Sub cmdSave_Click()
'--------------------------------------------------------------
' Save the data to the data base

Dim lngCusId As Long

' Has the user entered at least a last name?

If Nz(txtLastName) = "" Then
   MsgBox "Please enter a customer name!"
   txtLastName.SetFocus
   Exit Sub
End If

' Save command

DoCmd.RunCommand (acCmdSaveRecord)

' The primary key of the saved entity is stored in a variable.
' This is used to activate the saved entity in the list.
' Otherwise after "Requery" the first entity of the list
' is activated. This would confuse the user, because the
' data displayed in the form are not the data of the entity
' that is selected in the list.

lngCusId = Me!cus_id

' Refresh the list
' (the FIRST entry of the list is activated now!)

lstCustomers.Enabled = True
lstCustomers.Requery

' Activate the just saved entity in the list again ...

lstCustomers.SetFocus
lstCustomers = lngCusId

' ... and show its data in the form.

Call lstCustomers_AfterUpdate

End Sub

Private Sub cmdStartform_Click()
'--------------------------------------------------------------
DoCmd.OpenForm "frmStart"
End Sub

Private Sub Form_Open(Cancel As Integer)
'--------------------------------------------------------------
' This form may be opend
'  -  either directly by a click in the start form or on the ribbon
'  -  or "indirectly" by a double click from "another" form.

' In that case, the entity, that was double clicked in the other form
' shall be displayed here - instead of the first entry from the list,
' which is displayed, if the form is simply opend from the start form or
' from the ribbon.

' The primary key of the double clicked entity is sent from the other
' form to this form via a variable called "OpenArgs" (=opening arguments).
' Which form that was, doesn't matter. The code works for any other form,
' that sends an "OpenArgs".

 ' To check this, have a look to the procedure
 ' txtName_DblClick in the form frmHRplanning1

Me!lstCustomers.SetFocus

If IsNull(OpenArgs) Then   ' The form was opend from the start form
                           ' or from the ribbon because OpenArgs is empty

   ' Activate the first line of the list and show the data of that
   ' entity in the form.

   If Nz(lstCustomers.ListCount) > 0 Then   ' erste Zeile anzeigen
      Me!lstCustomers = Me!lstCustomers.ItemData(0)
      Call lstCustomers_AfterUpdate
   End If

Else                       ' The form was opend by a double click
                           ' in another form because OpenArgs is NOT empty

   ' Activate that line of the list, that contains the entity,
   ' that was double clicked in the other form.
   ' (The entity to be activated is identified by its primary key,
   '  which is sent via OpenArgs!)
   
   Me!lstCustomers = OpenArgs
   Call lstCustomers_AfterUpdate
   
End If

' Enable all controls

cmdNew.Enabled = True
cmdSave.Enabled = True
cmdDelete.Enabled = True
lstCustomers.Enabled = True

' You can use the tab-key to move the input marker from box to box.
' The following command defines, what should happen, if you press
' the tab-key in the last box on the form.
' "1" means: "Jump back to the first box on the form!"

Me.Cycle = 1

End Sub

Private Sub lstCustomers_AfterUpdate()
'--------------------------------------------------------------
' Show the data of that entity, that was selected in the list, in the form

' The following line of code was a bit "compressed" in comparison to
' the code, that was automatically generated by the list box wizard.
' (see step 7)

' The following line of code means:
' If the list lstCustomers is not emtpy ("Not IsNull"), then ...
' ... search within the recordset (=the data source) of the current form ("Me")
' for the first value of "cus_id" (=the primary key in tblCustomer) that is equal
' to that one, that is selceted in the list box lstCustomers ("Me!lstCustomers")
' and display its data in the text boxes of the form.

If Not IsNull(lstCustomers) Then Me.Recordset.FindFirst "cus_id=" & Me!lstCustomers

' Enable the buttons, which may have been disabled before

cmdDelete.Enabled = True
cmdNew.Enabled = True

End Sub

Private Sub txtLastName_BeforeUpdate(Cancel As Integer)
'--------------------------------------------------------------
' The following code is very short, but needs a lot of explanation.
' Well - let's start:

' The storage of data in the data base may not only be executed with
' the command "DoCmd.RunCommand (acCmdSaveRecord)" which you know
' from the procedure cmdSave_Click. This is only the "explicit" method,
' which is executed by the user, who clicks on the "save" button.

' There is also an "implicit" storage method. It is executed, when
' you have entered data into a table (using the text boxes in a form)
' and then switch to another data record (by clicking into the list box).
' Access then assumes, that you are ready with editing the data
' and stores them.
' BUT: If the user has not yet entered all the necessary data,
'      this implicit storage must be prohibitet!
' This is done by this procedure.
' It is executed automatically by Access "before update", that means,
' before the storage (may be explicit / may be implicit!!) is executed.
' You can prohibit the execution of the storage by setting the argument
' "Cancel" to "True".

' Exactly that is done with the following code: If the user hasn't entered a
' last name (=necessary data!), the storage is prohibited!
' That's all.

If Nz(Me!txtLastName) = "" Then
   MsgBox "Please enter a name or press the Esc-key!"
   Cancel = True
End If

End Sub

========================================================
Code of the form 'frmHRplanning1_sfmEmployees'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmHRplanning1_sfmEmployees"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Option Compare Database

' ===============================================================
' Sorry ...
' ... the comments are not yet completely translated into English
' ===============================================================

Private Sub cmdDelete_Click()
'--------------------------------------------------------------
Dim lngAnswer As Long
Dim strMsgtext As String
Dim strSQL As String

' Sicherheitsfrage
strMsgtext = "Do you really want to delete the assignment?"
lngAnswer = MsgBox(strMsgtext, vbYesNo + vbDefaultButton2)

' Lschen
If lngAnswer = vbYes Then
   strSQL = "DELETE FROM tblEmp_Ord WHERE ord_id_f=" & _
            CStr(Parent!lstOrders) & _
            " AND emp_id_f=" & _
            CStr(Me!emp_id)
   'MsgBox strSQL
   CurrentDb.Execute strSQL
   Forms!frmHRplanning!frmHRplanning1.Requery
   Forms!frmHRplanning!frmHRplanning2.Requery
End If

End Sub

Private Sub Form_Open(Cancel As Integer)

' You can use the tab-key to move the input marker from box to box.
' The following command defines, what should happen, if you press
' the tab-key in the last box on the form.
' "1" means: "Jump back to the first box on the form!"

Me.Cycle = 1

End Sub

Private Sub txtLastName_Click()
'--------------------------------------------------------------
Dim rs As DAO.Recordset
Dim lngRecordnumber As Long

' Der Click auf den Mitarbeiternamen soll diesen Namen im Unterformular "frmHRplanning2" auswhlen
' und dort aber auch gleich bewirken, dass die zu diesem Mitarbeiter gehrigen Auftrge angezeigt werden.
' Zu diesem Zweck muss ein Click in die Mitarbeiterliste simuliert werden - und zwar durch den Aufruf der
' Prozedur mitarbeiterliste_AfterUpdate.
' Das ist aber nicht so ohne weiteres mglich. Es muss zunchst eine Public Prozedur im bergeordneten
' Formular aufgerufen werden, die wiederum eine Public Prozedur in ihrem bergeordenten Formular aufruft.
' Das ist dann das Startformular "frmHRplanning". Die Prozedur dort kann dann letztendlich die Prozedur
' public_mitarbeiterliste_AfterUpdate im Unterformular "frmHRplanning2" aufrufen.
' Dass ist ein ziemlicher Irrweg - aber anders habe ich es nicht hingekriegt ...

Forms!frmHRplanning!frmHRplanning2!lstEmployees = Me!emp_id
Forms!frmHRplanning!frmHRplanning2!lstEmployees.SetFocus
Call Parent.public_personalplanung1

' Anzeige der Daten, damit sie mittels "Speichern" gendert werden knnen

Parent.Parent!txtFrom = Me!txtFrom
Parent.Parent!txtTo = Me!txtTo
Parent.Parent!txtRemark = Me!txtRemark

'funktioniert NICHT:
'Forms!frmHRplanning!frmHRplanning2!mitarbeiterliste.SetFocus
'SendKeys "{UP}"
'SendKeys "{DOWN}"

'funktioniert auch NICHT:
'Set rst = CurrentDb.OpenRecordset("tblEmployee", dbOpenDynaset, dbReadOnly)
'rst.FindFirst "emp_id = " & Cstr(Me!emp_id)
'recordnumber = rst.AbsolutePosition + 1
' AbsolutePosition liefert Null fr den ersten Datensatz - darum +1 !
'DoCmd.GoToRecord acDataForm, "frmHRplanning!frmHRplanning2", acGoTo, recordnumber
'rst.Close

'funktioniert auch NICHT:
'Set rst = Forms!frmHRplanning!frmHRplanning2.Recordset.Clone
'rst.FindFirst "emp_id = " & Cstr(Me!emp_id)
'If Not rst.EOF Then Forms!frmHRplanning!frmHRplanning2.Bookmark = rst.Bookmark
'rst.Close

End Sub

========================================================
Code of the form 'frmZZOrderDates'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmZZOrderDates"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database
Option Explicit

Private Sub cmdStart_Click()
' ------------------------------------------------------------
' Generation of realistic order date and status

Dim rs As DAO.Recordset
Dim datBegin As Date, datEnd As Date
Dim datDate As Date
Dim datFrom As Date, datTo As Date
Dim dblRandom As Double

' OrderStatus:
' 1 = offered
' 2 = requested
' 3 = charged
' 4 = done
' 5 = in the works
' 6 = cancelled

If MsgBox("Do you REALLY want to change ALL the dates?", vbYesNo + vbDefaultButton2) = vbNo Then Exit Sub

datBegin = txtDate - 60
datEnd = txtDate + 60

Randomize

' tblOrders
' ---------

Set rs = CurrentDb.OpenRecordset("tblOrder", dbOpenDynaset)
rs.MoveFirst

Do Until rs.EOF

   datDate = datBegin + Int((datEnd - datBegin) * Rnd)
   datFrom = datDate + 7 + Int(5 * Rnd)
   datTo = datDate + 13 + Int(5 * Rnd)
   
   rs.Edit
   rs!ord_date = datDate
   rs!ord_from = datFrom
   rs!ord_to = datTo
   dblRandom = Rnd
   
   If datTo <= Date Then     ' -------- Past
   
      Select Case dblRandom
         Case Is < 0.05     ' cancelled
            rs!ost_id_f = 6
      
         Case Is < 0.25     ' offered
            rs!ost_id_f = 1
      
         Case Is < 0.65     ' done
            rs!ost_id_f = 4
      
         Case Else          ' charged
            rs!ost_id_f = 3
   
      End Select
   
   End If
   
   If datFrom <= Date And Date <= datTo Then ' -------- Current
   
      Select Case dblRandom
         Case Is < 0.05     ' cancelled
            rs!ost_id_f = 6
      
         Case Is < 0.25     ' requested
            rs!ost_id_f = 2
      
         Case Else          ' in the works
            rs!ost_id_f = 5
   
      End Select
   
   End If
   
   If Date <= datFrom Then   ' -------- Future
   
      Select Case dblRandom
         Case Is < 0.6      ' requested
            rs!ost_id_f = 2
      
         Case Else          ' offered
            rs!ost_id_f = 1
   
      End Select
   
   End If
   
   
   rs.Update
   rs.MoveNext
Loop

rs.Close
Set rs = Nothing

' tblEmp_Ord
' ----------

Set rs = CurrentDb.OpenRecordset("tblEmp_Ord", dbOpenDynaset)
rs.MoveFirst

Do Until rs.EOF
   datFrom = DLookup("ord_from", "tblOrder", "ord_id=" & CStr(rs!ord_id_f))
   datTo = DLookup("ord_to", "tblOrder", "ord_id=" & CStr(rs!ord_id_f))
   rs.Edit
   rs!empord_from = datFrom + Int(3 * Rnd)
   rs!empord_to = datTo - Int(3 * Rnd)
   rs.Update
   rs.MoveNext
Loop

rs.Close
Set rs = Nothing

End Sub

Private Sub Form_Open(Cancel As Integer)
txtDate = Date
End Sub

========================================================
Code of the form 'frmOrders'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmOrders"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database
Option Explicit

Private Sub cmdClose_Click()
'--------------------------------------------------------------
' Close the form

DoCmd.Close

End Sub

Private Sub cmdHelp_Click()
'--------------------------------------------------------------
' Open the help form

DoCmd.OpenForm "frmHelp", , , , , , "orders"

End Sub

Private Sub cmdStartform_Click()
'--------------------------------------------------------------
' Open the start form

DoCmd.OpenForm "frmStart"

End Sub

Private Sub Form_Open(Cancel As Integer)
'--------------------------------------------------------------
' This form may be opend
'  -  either directly by a click in the start form or on the ribbon
'  -  or "indirectly" by a double click from "another" form.

' In that case, the entity, that was double clicked in the other form
' shall be displayed here - instead of the first entry from the list,
' which is displayed, if the form is simply opend from the start form or
' from the ribbon.

' The primary key of the double clicked entity is sent from the other
' form to this form via a variable called "OpenArgs" (=opening arguments).
' Which form that was, doesn't matter. The code works for any other form,
' that sends an "OpenArgs".

Me!lstCustomers.SetFocus

If IsNull(OpenArgs) Then   ' The form was opend from the start form
                           ' or from the ribbon because OpenArgs is empty


   ' Activate the first line of the list and show the data of that
   ' entity in the form.
   

   If Nz(lstCustomers.ListCount) > 0 Then   ' erste Zeile anzeigen
      Me!lstCustomers = Me!lstCustomers.ItemData(0)
      Call lstCustomers_AfterUpdate
   End If

Else                       ' The form was opend by a double click
                           ' in another form because OpenArgs is NOT empty

   ' Activate that line of the list, that contains the entity,
   ' that was double clicked in the other form.
   ' (The entity to be activated is identified by its primary key,
   '  which is sent via OpenArgs!)
   
   Me!lstCustomers = OpenArgs
   Call lstCustomers_AfterUpdate
End If

' You can use the tab-key to move the input marker from box to box.
' The following command defines, what should happen, if you press
' the tab-key in the last box on the form.
' "1" means: "Jump back to the first box on the form!"

Me.Cycle = 1

End Sub

Private Sub lstCustomers_AfterUpdate()
'--------------------------------------------------------------
' Show the data of that entity, that was selected in the list, in the form

' The following line of code was a bit "compressed" in comparison to
' the code, that was automatically generated by the list box wizard.

' The following line of code means:
' If the list lstCustomers is not emtpy ("Not IsNull"), then ...
' ... search within the recordset (=the data source) of the current form ("Me")
' for the first value of "cus_id" (=the primary key in tblEmployee) that is equal
' to that one, that is selceted in the list box lstCustomers ("Me!lstCustomers")
' and display its data in the text boxes of the form

If Not IsNull(lstCustomers) Then Me.Recordset.FindFirst "cus_id=" & CStr(Me!lstCustomers)

End Sub

Private Sub txtName_DblClick(Cancel As Integer)
'--------------------------------------------------------------
' Open the form frmCustomers and display the data of that
' customer there, that was double clicked here!
' (identified by its primary key cus_id)

' "Me!cus_id" is the argument, that appears as "OpenArgs" in
' Form_Open in frmCustomers!

DoCmd.OpenForm "frmCustomers", , , , , , Me!cus_id

End Sub

========================================================
Code of the form 'frmOrderProcessingAfterStep3'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmOrderProcessingAfterStep3"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database
Option Explicit

Private Sub lstOrders_AfterUpdate()
'--------------------------------------------------------------
' This code is automatically generated by the list box wizard.
' It is executed every time, when another entity is selected
' in the list (="after update" of the list) - either by clicking
' with the mouse or by pressing the "up" key or the "down" key.
' Its objective is to display the data of that entity, that
' was selected in the list.
' The selected entity is found using its primary key!
' (see the line "rs.FindFirst ...")

' The code contains lots of terms, which need to be explained:
' ...........................................................
' A "recordset" is a temporary copy of data from the data base.
' It is used to find the entity, that was selected in the list.

' A "Clone" is an identical copy of a recordset.

' A "bookmark" is a pointer to a certain data record in the data base.
' It is used to navigate within the data base (if you "point to"
' data, they are dispalyed in the form!)

' "EOF"   is an abbrevation for "end-of-file".
'         (in this case it means "end of the recordset")
' "Str"   changes the number (primary key) into a string.
' "Nz"    sets the found number to zero (0), if the selected
'         entity was not found in the data base.
' "Me"    means the form itself ("Hi - it's me!")

Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[ord_id] = " & Str(Nz(Me![lstOrders], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

End Sub


========================================================
Code of the form 'frmOrderProcessingAfterStep4'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmOrderProcessingAfterStep4"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database
Option Explicit

Private Sub cmdClose_Click()
'--------------------------------------------------------------
' Close the form

DoCmd.Close

End Sub

Private Sub cmdDelete_Click()
'--------------------------------------------------------------
' This code is automatically generated by the button wizard.
' The lines with an apostroph at the beginning may be deleted.
' (see step 5!)

'On Error GoTo Err_cmdDelete_Click


    DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdDeleteRecord

'Exit_cmdDelete_Click:
'    Exit Sub

'Err_cmdDelete_Click:
'    MsgBox Err.Description
'    Resume Exit_cmdDelete_Click

End Sub

Private Sub cmdNew_Click()
'--------------------------------------------------------------
' This code is automatically generated by the button wizard.
' The lines with an apostroph at the beginning may be deleted.
' (see step 5!)

'On Error GoTo Err_cmdNew_Click


    DoCmd.GoToRecord , , acNewRec

'Exit_cmdNew_Click:
'    Exit Sub
'
'Err_cmdNew_Click:
'    MsgBox Err.Description
'    Resume Exit_cmdNew_Click
    
End Sub

Private Sub cmdSave_Click()
'--------------------------------------------------------------
' This code is automatically generated by the button wizard.
' The lines with an apostroph at the beginning may be deleted.
' (see step 5!)

'On Error GoTo Err_cmdSave_Click


    DoCmd.RunCommand acCmdSaveRecord

'Exit_cmdSave_Click:
'    Exit Sub
'
'Err_cmdSave_Click:
'    MsgBox Err.Description
'    Resume Exit_cmdSave_Click
    
End Sub

Private Sub lstOrders_AfterUpdate()
'--------------------------------------------------------------
' This code is automatically generated by the list box wizard.
' It is executed every time, when another entity is selected
' in the list (="after update" of the list) - either by clicking
' with the mouse or by pressing the "up" key or the "down" key.
' Its objective is to display the data of that entity, that
' was selected in the list.
' The selected entity is found using its primary key!
' (see the line "rs.FindFirst ...")

' The code contains lots of terms, which need to be explained:
' ...........................................................
' A "recordset" is a temporary copy of data from the data base.
' It is used to find the entity, that was selected in the list.

' A "Clone" is an identical copy of a recordset.

' A "bookmark" is a pointer to a certain data record in the data base.
' It is used to navigate within the data base (if you "point to"
' data, they are dispalyed in the form!)

' "EOF"   is an abbrevation for "end-of-file".
'         (in this case it means "end of the recordset")
' "Str"   changes the number (primary key) into a string.
' "Nz"    sets the found number to zero (0), if the selected
'         entity was not found in the data base.
' "Me"    means the form itself ("Hi - it's me!")

Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[ord_id] = " & Str(Nz(Me![lstOrders], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

End Sub


========================================================
Code of the form 'frmExport'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmExport"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database
Option Explicit

Private Sub cmdStart_Click()
' Writes the VBA code of all forms and modules to an export file "Code_Export.txt"

Dim objObject As Object
Dim mdlModule As Module
Dim modModules As Modules
Dim lngModuleNr As Long
Dim strExportFile As String

strExportFile = Application.CurrentProject.Path & "\Code_Export.txt"

' Does the file 'Export_Code.txt' already exist?

If Dir(strExportFile) <> "" Then
   
   ' If yes - is it not empty?
   
   If FileLen(strExportFile) > 0 Then
      
      MsgBox "The file 'Export_Code.txt' exists already" & vbCrLf & _
             "and is not empty!", vbExclamation, "WARNING"
      Exit Sub
   
   End If
   
End If

' If it does not exist or if it exists and is empty:
' Write the title line

Open strExportFile For Output As #1
Print #1, "++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
Print #1, "++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
Print #1, "VBA Code of the data base '" & Application.CurrentProject.Name & "'"
Print #1, Date
Print #1, "++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
Print #1, "++++++++++++++++++++++++++++++++++++++++++++++++++++++++"

Close #1

Set modModules = Application.Modules

' Loop over all forms
' ===================

For Each objObject In CurrentProject.AllForms
   
   ' Loop over all modules
   
   For lngModuleNr = 0 To modModules.Count - 1
   
      'MsgBox modModules(lngModuleNr).Name & " / " & objObject.Name
      
      ' Does a module exist for the form objObject?
      
      If modModules(lngModuleNr).Name = "Form_" & objObject.Name Then
      
            ' Write the module code to a temporary file 'temptemp.txt'
            
            DoCmd.OutputTo acOutputModule, _
                           modModules(lngModuleNr).Name, _
                           acFormatTXT, _
                           Application.CurrentProject.Path & "\temptemp.txt"

            ' Append the temporary file to the export file 'Code_Export.txt'
            
            WriteFile strExportFile, _
                      ReadFile(strExportFile) & vbCrLf & _
                      "========================================================" & vbCrLf & _
                      "Code of the form '" & objObject.Name & "'" & vbCrLf & _
                      "========================================================" & vbCrLf & _
                      ReadFile(Application.CurrentProject.Path & "\temptemp.txt")

      
      End If
      
   Next lngModuleNr
      
Next objObject

' Loop over all modules
' =====================

For Each objObject In CurrentProject.AllModules

   ' Write the module code to a temporary file 'temptemp.txt'

   DoCmd.OutputTo acOutputModule, _
                  objObject.Name, _
                  acFormatTXT, _
                  Application.CurrentProject.Path & "\temptemp.txt"
   
   ' Append the temporary file to the export file 'Code_Export.txt'
            
   WriteFile strExportFile, _
             ReadFile(strExportFile) & vbCrLf & _
             "**********************************************************************" & vbCrLf & _
             "**********************************************************************" & vbCrLf & _
             "Code of the module '" & objObject.Name & "'" & vbCrLf & _
             "**********************************************************************" & vbCrLf & _
             "**********************************************************************" & vbCrLf & _
             ReadFile(Application.CurrentProject.Path & "\temptemp.txt")
   
Next objObject

Kill Application.CurrentProject.Path & "\temptemp.txt"

MsgBox "Ready!" & vbCrLf & lngModuleNr - 1 & " form(s) and " & vbCrLf & _
                           CurrentProject.AllModules.Count & " module(s) exported to 'Export_Code.txt'!"

End Sub

Function ReadFile(ByRef Path As String) As String
' Quelle: http://vb-tec.de/readfile.htm

Dim FileNr As Long
  
FileNr = FreeFile

Open Path For Binary As #FileNr
ReadFile = Space$(LOF(FileNr))
Get #FileNr, , ReadFile
Close #FileNr

End Function

Sub WriteFile(ByRef Path As String, ByRef Text As String)
' Quelle: http://vb-tec.de/speicher.htm

Dim FileNr As Long
  
FileNr = FreeFile
Open Path For Output As #FileNr
Print #FileNr, Text;
Close #FileNr

End Sub

========================================================
Code of the form 'frmOrderProcessingAfterStep5'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmOrderProcessingAfterStep5"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database
Option Explicit

Private Sub cmdClose_Click()
'--------------------------------------------------------------
' Close the form

DoCmd.Close

End Sub

Private Sub cmdDelete_Click()
'--------------------------------------------------------------
' Attention: The needless code from step 4 was deleted!

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord

End Sub

Private Sub cmdNew_Click()
'--------------------------------------------------------------
' Attention: The needless code from step 4 was deleted!

DoCmd.GoToRecord , , acNewRec

End Sub

Private Sub cmdSave_Click()
'--------------------------------------------------------------
' Attention: The needless code from step 4 was deleted!

DoCmd.RunCommand acCmdSaveRecord

End Sub

Private Sub lstOrders_AfterUpdate()
'--------------------------------------------------------------
' This code is automatically generated by the list box wizard.
' It is executed every time, when another entity is selected
' in the list (="after update" of the list) - either by clicking
' with the mouse or by pressing the "up" key or the "down" key.
' Its objective is to display the data of that entity, that
' was selected in the list.
' The selected entity is found using its primary key!
' (see the line "rs.FindFirst ...")

' The code contains lots of terms, which need to be explained:
' ...........................................................
' A "recordset" is a temporary copy of data from the data base.
' It is used to find the entity, that was selected in the list.

' A "Clone" is an identical copy of a recordset.

' A "bookmark" is a pointer to a certain data record in the data base.
' It is used to navigate within the data base (if you "point to"
' data, they are dispalyed in the form!)

' "EOF"   is an abbrevation for "end-of-file".
'         (in this case it means "end of the recordset")
' "Str"   changes the number (primary key) into a string.
' "Nz"    sets the found number to zero (0), if the selected
'         entity was not found in the data base.
' "Me"    means the form itself ("Hi - it's me!")

Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[ord_id] = " & Str(Nz(Me![lstOrders], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

End Sub


========================================================
Code of the form 'frmOrderProcessingAfterStep6'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmOrderProcessingAfterStep6"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database
Option Explicit

Private Sub cmdClose_Click()
'--------------------------------------------------------------
' Close the form

DoCmd.Close

End Sub

Private Sub cmdDelete_Click()
'--------------------------------------------------------------

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord

' Attention:
' ..........
' The following line must be added to the automatically generated code.
' Otherwise the deleted employee doesn't disappear from the list.

lstOrders.Requery

End Sub

Private Sub cmdNew_Click()
'--------------------------------------------------------------

DoCmd.GoToRecord , , acNewRec

End Sub

Private Sub cmdSave_Click()
'--------------------------------------------------------------

DoCmd.RunCommand acCmdSaveRecord

' Attention:
' ..........
' The following line must be added to the automatically generated code.
' Otherwise a newly generated employee doesn't appear in the list.

lstOrders.Requery

End Sub

Private Sub lstOrders_AfterUpdate()
'--------------------------------------------------------------
' This code is automatically generated by the list box wizard.
' It is executed every time, when another entity is selected
' in the list (="after update" of the list) - either by clicking
' with the mouse or by pressing the "up" key or the "down" key.
' Its objective is to display the data of that entity, that
' was selected in the list.
' The selected entity is found using its primary key!
' (see the line "rs.FindFirst ...")

' The code contains lots of terms, which need to be explained:
' ...........................................................
' A "recordset" is a temporary copy of data from the data base.
' It is used to find the entity, that was selected in the list.

' A "Clone" is an identical copy of a recordset.

' A "bookmark" is a pointer to a certain data record in the data base.
' It is used to navigate within the data base (if you "point to"
' data, they are dispalyed in the form!)

' "EOF"   is an abbrevation for "end-of-file".
'         (in this case it means "end of the recordset")
' "Str"   changes the number (primary key) into a string.
' "Nz"    sets the found number to zero (0), if the selected
'         entity was not found in the data base.
' "Me"    means the form itself ("Hi - it's me!")

Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[ord_id] = " & Str(Nz(Me![lstOrders], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

End Sub


========================================================
Code of the form 'frmOrderProcessingAfterStep7'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmOrderProcessingAfterStep7"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database
Option Explicit

Private Sub cmdClose_Click()
'--------------------------------------------------------------
' Close the form

DoCmd.Close

End Sub

Private Sub cmdDelete_Click()
'--------------------------------------------------------------

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord

' Attention:
' ..........
' The following line must be added to the automatically generated code.
' Otherwise the deleted employee doesn't disappear from the list.

lstOrders.Requery

End Sub

Private Sub cmdNew_Click()
'--------------------------------------------------------------

DoCmd.GoToRecord , , acNewRec

End Sub

Private Sub cmdSave_Click()
'--------------------------------------------------------------

DoCmd.RunCommand acCmdSaveRecord

' Attention:
' ..........
' The following line must be added to the automatically generated code.
' Otherwise a newly generated employee doesn't appear in the list.

lstOrders.Requery

End Sub

Private Sub lstOrders_AfterUpdate()
'--------------------------------------------------------------
' This code is automatically generated by the list box wizard.
' It is executed every time, when another entity is selected
' in the list (="after update" of the list) - either by clicking
' with the mouse or by pressing the "up" key or the "down" key.
' Its objective is to display the data of that entity, that
' was selected in the list.
' The selected entity is found using its primary key!
' (see the line "rs.FindFirst ...")

' The code contains lots of terms, which need to be explained:
' ...........................................................
' A "recordset" is a temporary copy of data from the data base.
' It is used to find the entity, that was selected in the list.

' A "Clone" is an identical copy of a recordset.

' A "bookmark" is a pointer to a certain data record in the data base.
' It is used to navigate within the data base (if you "point to"
' data, they are dispalyed in the form!)

' "EOF"   is an abbrevation for "end-of-file".
'         (in this case it means "end of the recordset")
' "Str"   changes the number (primary key) into a string.
' "Nz"    sets the found number to zero (0), if the selected
'         entity was not found in the data base.
' "Me"    means the form itself ("Hi - it's me!")

Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[ord_id] = " & Str(Nz(Me![lstOrders], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

End Sub

========================================================
Code of the form 'frmOrderProcessing'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmOrderProcessing"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Option Compare Database

Private Sub cboOrderStatus_AfterUpdate()
'--------------------------------------------------------------
' By changing the value of the combo box the user has started a
' so-called "transaction" (=a change of data in the data base).
' This transaction must be finished immediately by calling the
' save command; otherwise an error may occur if the user makes
' further changes without first saving the changes made here.

DoCmd.RunCommand (acCmdSaveRecord)

End Sub

Private Sub cboOrderStatus_Dirty(Cancel As Integer)
'--------------------------------------------------------------
' The user may have changed the value in the combo box unintentionally.
' Therefore he is asked, if he really wants to make the change.
' But he is of course not asked, if he enters a new value for the
' first time (=no OldValue).

If IsNull(cboOrderStatus.OldValue) Then Exit Sub
If MsgBox("Do you really want to change the order status?", vbYesNo + vbDefaultButton2) = vbNo Then Cancel = True
End Sub

Private Sub cboOrderStatus_GotFocus()
'--------------------------------------------------------------
' The content of the combo box (=the list of data, which are
' displayed in the combo box) may have been changed in another form.
' (data may be added, changed or deleted there)
' Therefore the content of the combo box is always refreshed, if it
' gets the focus (=if it is clicked with the mouse or if it is
' activated using the tab-key).

cboOrderStatus.Requery

End Sub

Private Sub cboCustomer_AfterUpdate()
'--------------------------------------------------------------
' By changing the value of the combo box the user has started a
' so-called "transaction" (=a change of data in the data base).
' This transaction must be finished immediately by calling the
' save command; otherwise an error may occur if the user makes
' further changes without first saving the changes made here.

DoCmd.RunCommand (acCmdSaveRecord)

End Sub

Private Sub cboCustomer_DblClick(Cancel As Integer)

' The user may have deleted the name of the customer and then - without saving -
' make a double click into the combo box. Then the customer form would open anyway -
' but there would occur a runtime error, when closing it again.

If cboCustomer = "" Then
   MsgBox "Please select a customer!"
   Cancel = True
   Exit Sub
End If

DoCmd.RunCommand (acCmdSaveRecord)

DoCmd.OpenForm "frmCustomers", , , , , , Me!cboCustomer
End Sub

Private Sub cboCustomer_GotFocus()
'--------------------------------------------------------------
' If the content of the combo box had been changed in ANOTHER form,
' it must be refreshed here.

cboCustomer.Requery

End Sub

Private Sub cmdPrintOne_Click()
DoCmd.OpenReport "rptOrder", acViewPreview, , "ord_id=" & Me!ord_id
End Sub

Private Sub cmdHelp_Click()
'--------------------------------------------------------------
' Show the form with the help information
' "orderprocessing" is the argument, that appears as "OpenArgs" in
' Form_Open in frmHelp! It is used to say the form frmHelp, which
' help information shall be shown.

DoCmd.OpenForm "frmHelp", , , , , , "orderprocessing"
End Sub

Private Sub cmdStartform_Click()
'--------------------------------------------------------------
DoCmd.OpenForm "frmStart"
End Sub

Private Sub lstOrders_AfterUpdate()
'--------------------------------------------------------------
'Show the data of the object, that was clicked in the list

If Not IsNull(lstOrders) Then Me.Recordset.FindFirst "ord_id=" & Me!lstOrders

cmdDelete.Enabled = True
cmdNew.Enabled = True

cmdPrintOne.Enabled = True

End Sub

Private Sub cmdDelete_Click()
'--------------------------------------------------------------
Dim lngAnswer As Long
Dim strMsgtext As String

' Safety question

strMsgtext = "Do you really want to delete the order " & Me!txtNumber & "?"
lngAnswer = MsgBox(strMsgtext, vbYesNo + vbDefaultButton2)

' Execute the delete
' (Before the order can be deleted, all references in other tables
'  to this order must be deleted!!)

If lngAnswer = vbYes Then
   CurrentDb.Execute "DELETE FROM tblMat_Ord WHERE ord_id_f=" & CStr(Me!ord_id)
   CurrentDb.Execute "DELETE FROM tblEmp_Ord WHERE ord_id_f=" & CStr(Me!ord_id)
   CurrentDb.Execute "DELETE FROM tblOrder WHERE ord_id=" & CStr(Me!ord_id)
   lstOrders.Requery      ' Refresh the list
   Requery                ' Refresh the form
   lstOrders.SetFocus
   If Nz(lstOrders.ListCount) > 0 Then   ' Show the first line of the list
      Me!lstOrders = Me!lstOrders.ItemData(0)
      Call lstOrders_AfterUpdate
   End If
End If

End Sub

Private Sub cmdNew_Click()
'--------------------------------------------------------------

lstOrders = Null

DoCmd.GoToRecord , , acNewRec
txtDate = Date
cboCustomer.SetFocus

cboOrderStatus = Nz(DLookup("ost_id", "tblOrderStatus", "ost_name='requested'"), Null)

' A new order must first be saved, before material can be entered!
' Therefore frmOrderProcessing_sfmMaterials is locked.
' It will be unlocked in cmdSave_Click.

Forms!frmOrderProcessing!frmOrderProcessing_sfmMaterials.Locked = True

cmdNew.Enabled = False
cmdDelete.Enabled = False
lstOrders.Enabled = False

cmdPrintOne.Enabled = False

End Sub

Private Sub cmdClose_Click()
'--------------------------------------------------------------
DoCmd.Close
End Sub

Private Sub cmdSave_Click()
'--------------------------------------------------------------
Dim lngOrdId As Long

' Safety questions

If Nz(txtDescription) = "" Then
   MsgBox "Please enter an order description!"
   txtDescription.SetFocus
   Exit Sub
End If
If IsNull(cboCustomer) Then
   MsgBox "Please select a customer!"
   cboCustomer.SetFocus
   Exit Sub
End If
If IsNull(cboOrderStatus) Then
   MsgBox "Please select a status!"
   cboOrderStatus.SetFocus
   Exit Sub
End If
If Nz(txtNumber) = "" Then
   MsgBox "Please enter an order number!"
   txtNumber.SetFocus
   Exit Sub
End If

' Execute the save

DoCmd.RunCommand (acCmdSaveRecord)

' The primary key of the just saved data record is stored
' in the variabale "lngOrdId". It is needed at the end of the procedure
' to mark the just saved order in the list.

lngOrdId = Me!ord_id

' Refresh the list

lstOrders.Enabled = True
lstOrders.Requery

' Mark the just saved order in the list

lstOrders.SetFocus
lstOrders = lngOrdId
Call lstOrders_AfterUpdate

' Now material can be entered

Forms!frmOrderProcessing!frmOrderProcessing_sfmMaterials.Locked = False

End Sub

Private Sub cboCustomer_Dirty(Cancel As Integer)
'--------------------------------------------------------------
' Safety measure against unintentional changes of the customer
' It is not executed at the very first input of a customer ("OldValue=Null")

If IsNull(cboCustomer.OldValue) Then Exit Sub
If MsgBox("Do you really want to change the customer?", vbYesNo + vbDefaultButton2) = vbNo Then Cancel = True
End Sub

Private Sub Form_Open(Cancel As Integer)
'--------------------------------------------------------------
' If the form is opened via double click from another form
' (= "OpenArgs" contains the corresponding primary key!), the order,
' that was clicked there, shall be shown here in this form.
' If the form is opend directly (="OpenArgs=Null"),
' the first order from the list shall be shown.

Me!lstOrders.SetFocus

If IsNull(OpenArgs) Then

   If Nz(lstOrders.ListCount) > 0 Then   ' erste Zeile anzeigen
      Me!lstOrders = Me!lstOrders.ItemData(0)
      Call lstOrders_AfterUpdate
   End If

Else
   
   Me!lstOrders = OpenArgs
   Call lstOrders_AfterUpdate

End If

cmdDelete.Enabled = True
cmdNew.Enabled = True

' You can use the tab-key to move the input marker from box to box.
' The following command defines, what should happen, if you press
' the tab-key in the last box on the form.
' "1" means: "Jump back to the first box on the form!"

Me.Cycle = 1

End Sub

========================================================
Code of the form 'frmHRplanning'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmHRplanning"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Option Compare Database

Public Sub public_pp_mitarbeiter()
'--------------------------------------------------------------
Call Me.frmHRplanning2.Form.public_lstEmployees_AfterUpdate
End Sub

Public Sub public_pp_auftraege()
'--------------------------------------------------------------
Call Me.frmHRplanning1.Form.public_lstOrders_AfterUpdate
End Sub

Private Sub cmdHelp_Click()
'--------------------------------------------------------------
DoCmd.OpenForm "frmHelp", , , , , , "hrplanning"
End Sub

Private Sub cmdClose_Click()
'--------------------------------------------------------------
DoCmd.Close
End Sub

Private Sub cmdSave_Click()
'--------------------------------------------------------------
Dim rs As DAO.Recordset
Dim lngOrdId As Long
Dim lngEmpId As Long

lngOrdId = Forms!frmHRplanning!frmHRplanning1!ord_id
lngEmpId = Forms!frmHRplanning!frmHRplanning2!emp_id

If Nz(txtFrom) = "" Then
   MsgBox "please enter a start time!"
   txtFrom.SetFocus
   Exit Sub
End If

If Nz(txtTo) = "" Then
   MsgBox "Please enter an end time!"
   txtTo.SetFocus
   Exit Sub
End If

If txtTo < txtFrom Then
   MsgBox "Begin must be before the end!"
   txtFrom.SetFocus
   Exit Sub
End If

Set rs = CurrentDb.OpenRecordset("tblEmp_Ord", dbOpenDynaset)
rs.FindFirst "ord_id_f=" & CStr(lngOrdId) & " AND emp_id_f=" & CStr(lngEmpId)

If rs.NoMatch Then   ' Add a new entry (up to now the employee doesn't work for the order)
   
   rs.AddNew
   rs!ord_id_f = lngOrdId
   rs!emp_id_f = lngEmpId
   rs!empord_from = txtFrom
   rs!empord_to = txtTo
   rs!empord_remark = txtRemark
   rs.Update
   Forms!frmHRplanning!frmHRplanning1.Requery
   Forms!frmHRplanning!frmHRplanning2.Requery

Else   ' Edit an existing entry (the employee works already for the order)
   
   rs.Edit
   rs!empord_from = txtFrom
   rs!empord_to = txtTo
   rs!empord_remark = txtRemark
   rs.Update
   Forms!frmHRplanning!frmHRplanning1.Requery
   Forms!frmHRplanning!frmHRplanning2.Requery

End If

rs.Close
Set rs = Nothing

End Sub

Private Sub cmdStartform_Click()
'--------------------------------------------------------------
DoCmd.OpenForm "frmStart"
End Sub

Private Sub Form_Open(Cancel As Integer)

' You can use the tab-key to move the input marker from box to box.
' The following command defines, what should happen, if you press
' the tab-key in the last box on the form.
' "1" means: "Jump back to the first box on the form!"

Me.Cycle = 1

End Sub

========================================================
Code of the form 'frmExecSQL'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmExecSQL"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database
Option Explicit


Private Sub cmdDelete_Click()
txtSqlbefehl.Value = ""
txtSqlbefehl.SetFocus
End Sub

Private Sub cmdAusfuehren_Click()
On Error GoTo fehler

If txtSqlbefehl <> "" Then

   DoCmd.RunSQL txtSqlbefehl.Value
   MsgBox "The command was successfully executed." & vbCrLf & _
          "Please check the effect in the data base!"

End If

Exit Sub
fehler:
    MsgBox Err.Description
    txtSqlbefehl.SetFocus
    
End Sub

========================================================
Code of the form 'frmCustomers_sfmContacts'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmCustomers_sfmContacts"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Option Compare Database

Private Sub cboContacttype_AfterUpdate()
'--------------------------------------------------------------
' By changing the value of the combo box the user has started a
' so-called "transaction" (=a change of data in the data base).
' This transaction must be finished immediately by calling the
' save command; otherwise an error may occur if the user makes
' further changes without first saving the changes made here.

DoCmd.RunCommand (acCmdSaveRecord)

End Sub

Private Sub cboContacttype_Dirty(Cancel As Integer)
'--------------------------------------------------------------
' The user may have changed the value in the combo box unintentionally.
' Therefore he is asked, if he really wants to make the change.
' But he is of course not asked, if he enters a new value for the
' first time (=no OldValue).

If IsNull(cboContactType.OldValue) Then Exit Sub
If MsgBox("Do you really want to change the contact type?", _
           vbYesNo + vbDefaultButton2) = vbNo Then Cancel = True

End Sub

Private Sub Contacttype_GotFocus()
'--------------------------------------------------------------
' The content of the combo box (=the list of data, which are
' displayed in the combo box) may have been changed in another form.
' (data may be added, changed or deleted there)
' Therefore the content of the combo box is always refreshed, if it
' gets the focus (=if it is clicked with the mouse or if it is
' activated using the tab-key).

cboContactType.Requery

End Sub

Private Sub cmdDelete_Click()
'--------------------------------------------------------------
Dim lngAnswer As Long
Dim strMsgtext As String

' In the last row (which is empty) there is nothig to be deleted

If IsNull(con_contact) Then Exit Sub

' Security question

strMsgtext = "Do you really want to delete the contact " & Me!con_contact & "?"
lngAnswer = MsgBox(strMsgtext, vbYesNo + vbDefaultButton2)

' Execute the delete command
' (The contact to be deleted is identified by his primary key!)

If lngAnswer = vbYes Then
   CurrentDb.Execute "DELETE FROM tblContact WHERE con_id=" & CStr(Me!con_id)
   Requery
End If

End Sub

Private Sub Form_Open(Cancel As Integer)
'--------------------------------------------------------------
' You can use the tab-key to move the input marker from box to box.
' The following command defines, what should happen, if you press
' the tab-key in the last box on the form.
' "1" means: "Jump back to the first box on the form!"

Me.Cycle = 1

End Sub

========================================================
Code of the form 'frmOrders_sfmOrders'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmOrders_sfmOrders"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Option Compare Database

Private Sub cboOrderStatus_AfterUpdate()
'--------------------------------------------------------------
' By changing the value of the combo box the user has started a
' so-called "transaction" (=a change of data in the data base).
' This transaction must be finished immediately by calling the
' save command; otherwise an error may occur if the user makes
' further changes without first saving the changes made here.

DoCmd.RunCommand (acCmdSaveRecord)

End Sub

Private Sub cboOrderStatus_Dirty(Cancel As Integer)
'--------------------------------------------------------------
' The user may have changed the value in the combo box unintentionally.
' Therefore he is asked, if he really wants to make the change.
' But he is of course not asked, if he enters a new value for the
' first time (=no OldValue).

If IsNull(cboOrderStatus.OldValue) Then Exit Sub
If MsgBox("Do you really want to change the order status?", vbYesNo + vbDefaultButton2) = vbNo Then Cancel = True

End Sub

Private Sub cboOrderStatus_GotFocus()
'--------------------------------------------------------------
' The content of the combo box (=the list of data, which are
' displayed in the combo box) may have been changed in another form.
' (data may be added, changed or deleted there)
' Therefore the content of the combo box is always refreshed, if it
' gets the focus (=if it is clicked with the mouse or if it is
' activated using the tab-key).

cboOrderStatus.Requery

End Sub

Private Sub Form_Open(Cancel As Integer)
' You can use the tab-key to move the input marker from box to box.
' The following command defines, what should happen, if you press
' the tab-key in the last box on the form.
' "1" means: "Jump back to the first box on the form!"

Me.Cycle = 1
End Sub

Private Sub txtDescription_DblClick(Cancel As Integer)
'--------------------------------------------------------------
' Open the form frmOrderProcessing and display the data of that
' order there, that was double clicked here!
' (identified by its primary key ord_id)

' "Me!ord_id" is the argument, that appears as "OpenArgs" in
' Form_Open in frmOrderProcessing!

DoCmd.OpenForm "frmOrderProcessing", , , , , , Me!ord_id
End Sub

========================================================
Code of the form 'frmMaterials'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmMaterials"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database
Option Explicit

' =============================================================
' Without comments!
'
' Please find out, what the different procedures do, by comparing
' them with similar procedures in other modules (frmCustomers,
' frmEmployees, frmOrderProcessing)
'
' =============================================================

Private Sub cboQuantityUnit_AfterUpdate()
'--------------------------------------------------------------
DoCmd.RunCommand (acCmdSaveRecord)
End Sub

Private Sub cboQuantityUnit_Dirty(Cancel As Integer)
'--------------------------------------------------------------
If IsNull(cboQuantityUnit.OldValue) Then Exit Sub
If MsgBox("Do you really want to change the quantity unit?", vbYesNo + vbDefaultButton2) = vbNo Then Cancel = True
End Sub

Private Sub cboQuantityUnit_GotFocus()
'--------------------------------------------------------------
cboQuantityUnit.Requery
End Sub

Private Sub cmdAll_Click()
'--------------------------------------------------------------
Dim strSQL As String

strSQL = "SELECT mat_id, mat_name FROM tblMaterial " & _
         "ORDER BY mat_name"

txtSearchTerm = ""

lstMaterials.RowSourceType = "Table/Query"
lstMaterials.RowSource = strSQL
lstMaterials.Requery

If Nz(lstMaterials.ListCount) > 0 Then
   Me!lstMaterials = Me!lstMaterials.ItemData(0)
   Call lstMaterials_AfterUpdate
End If

End Sub

Private Sub cmdHelp_Click()
'--------------------------------------------------------------
DoCmd.OpenForm "frmHelp", , , , , , "materials"
End Sub

Private Sub cmdDelete_Click()
'--------------------------------------------------------------
Dim lngAnswer As Long
Dim strMsgtext As String
Dim rs As DAO.Recordset

If IsNull(lstMaterials) Then
   MsgBox "Please select a material from the list!"
   lstMaterials.SetFocus
   Exit Sub
End If

If Nz(Me!txtName) = "" Then
   MsgBox "Please select a material from the list!"
   lstMaterials.SetFocus
   Exit Sub
End If

strMsgtext = "Do you really want to delete the material " & Me!txtName & "?"

' The following code demonstrates one possibility to find out,
' if there are references to the entity to be deleted in other tables.

' Attention: The code in cmdDelete_Click in module frmCustomers demonstrates
'            another possibility to find out, if there are references to
'            the entity to be deleted in other tables!

Set rs = CurrentDb.OpenRecordset("tblMat_Ord", dbOpenDynaset)
rs.FindFirst "mat_id_f=" & CStr(Me!mat_id)

If rs.NoMatch Then

   lngAnswer = MsgBox(strMsgtext, vbYesNo + vbDefaultButton2)
   rs.Close
   Set rs = Nothing
   If lngAnswer = vbNo Then Exit Sub
   CurrentDb.Execute "DELETE FROM tblMaterial WHERE mat_id=" & CStr(Me!mat_id)
   lstMaterials.Requery
   Requery
   lstMaterials.SetFocus
   If Nz(lstMaterials.ListCount) > 0 Then
      Me!lstMaterials = Me!lstMaterials.ItemData(0)
      Call lstMaterials_AfterUpdate
   End If
   
Else

   MsgBox "This material can not be deleted!" & vbCrLf & _
          "There are still orders with it."
   rs.Close
   Set rs = Nothing
   Exit Sub
   
End If

End Sub

Private Sub cmdNew_Click()
'--------------------------------------------------------------
lstMaterials = Null
DoCmd.GoToRecord , , acNewRec
txtName.SetFocus

cmdNew.Enabled = False
cmdDelete.Enabled = False
lstMaterials.Enabled = False

End Sub

Private Sub cmdClose_Click()
'--------------------------------------------------------------
DoCmd.Close
End Sub

Private Sub cmdSave_Click()
'--------------------------------------------------------------
Dim lngMatId As Long

If Nz(txtName) = "" Then
   MsgBox "Please enter a name!"
   txtName.SetFocus
   Exit Sub
End If

DoCmd.RunCommand acCmdSaveRecord
lngMatId = Me!mat_id

lstMaterials.Enabled = True
lstMaterials.Requery
lstMaterials.SetFocus

lstMaterials = lngMatId
Call lstMaterials_AfterUpdate

End Sub

Private Sub cmdSearch_Click()
'--------------------------------------------------------------
Dim strSQL As String

strSQL = "SELECT mat_id, mat_name FROM tblMaterial " & _
         "WHERE mat_name LIKE '*" & txtSearchTerm & "*' " & _
         "ORDER BY mat_name"

lstMaterials.RowSourceType = "Table/Query"
lstMaterials.RowSource = strSQL
lstMaterials.Requery

If Nz(lstMaterials.ListCount) > 0 Then
   Me!lstMaterials = Me!lstMaterials.ItemData(0)
   Call lstMaterials_AfterUpdate
End If

End Sub

Private Sub Form_Open(Cancel As Integer)
'--------------------------------------------------------------

Me!lstMaterials.SetFocus

If IsNull(OpenArgs) Then

   If Nz(lstMaterials.ListCount) > 0 Then
      Me!lstMaterials = Me!lstMaterials.ItemData(0)
      Call lstMaterials_AfterUpdate
   End If

Else
   Me!lstMaterials = OpenArgs
   Call lstMaterials_AfterUpdate
End If

cmdDelete.Enabled = True
cmdNew.Enabled = True

Me.Cycle = 1

End Sub

Private Sub lstMaterials_AfterUpdate()
'--------------------------------------------------------------

If Not IsNull(lstMaterials) Then Me.Recordset.FindFirst "mat_id=" & Me!lstMaterials

cmdDelete.Enabled = True
cmdNew.Enabled = True

End Sub

Private Sub txtName_BeforeUpdate(Cancel As Integer)

If Nz(Me!txtName) = "" Then
   MsgBox "Please enter a name or press the Esc-key!"
   Cancel = True
End If

End Sub

========================================================
Code of the form 'frmEmployeesAfterStep3'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmEmployeesAfterStep3"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database
Option Explicit

Private Sub lstEmployees_AfterUpdate()
'--------------------------------------------------------------
' This code is automatically generated by the list box wizard.
' It is executed every time, when another entity is selected
' in the list (="after update" of the list) - either by clicking
' with the mouse or by pressing the "up" key or the "down" key.
' Its objective is to display the data of that entity, that
' was selected in the list.
' The selected entity is found using its primary key!
' (see the line "rs.FindFirst ...")

' The code contains lots of terms, which need to be explained:
' ...........................................................
' A "recordset" is a temporary copy of data from the data base.
' It is used to find the entity, that was selected in the list.

' A "Clone" is an identical copy of a recordset.

' A "bookmark" is a pointer to a certain data record in the data base.
' It is used to navigate within the data base (if you "point to"
' data, they are dispalyed in the form!)

' "EOF"   is an abbrevation for "end-of-file".
'         (in this case it means "end of the recordset")
' "Str"   changes the number (primary key) into a string.
' "Nz"    sets the found number to zero (0), if the selected
'         entity was not found in the data base.
' "Me"    means the form itself ("Hi - it's me!")

Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[emp_id] = " & Str(Nz(Me![lstEmployees], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

End Sub

========================================================
Code of the form 'frmEmployeesAfterStep4'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmEmployeesAfterStep4"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database
Option Explicit

Private Sub cmdClose_Click()
'--------------------------------------------------------------
' Close the form

DoCmd.Close

End Sub

Private Sub cmdDelete_Click()
'--------------------------------------------------------------
' This code is automatically generated by the button wizard.
' The lines with an apostroph at the beginning may be deleted.
' (see step 5!)

'On Error GoTo Err_cmdDelete_Click


    DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdDeleteRecord

'Exit_cmdDelete_Click:
'    Exit Sub

'Err_cmdDelete_Click:
'    MsgBox Err.Description
'    Resume Exit_cmdDelete_Click

End Sub

Private Sub cmdNew_Click()
'--------------------------------------------------------------
' This code is automatically generated by the button wizard.
' The lines with an apostroph at the beginning may be deleted.
' (see step 5!)

'On Error GoTo Err_cmdNew_Click


    DoCmd.GoToRecord , , acNewRec

'Exit_cmdNew_Click:
'    Exit Sub
'
'Err_cmdNew_Click:
'    MsgBox Err.Description
'    Resume Exit_cmdNew_Click
    
End Sub

Private Sub cmdSave_Click()
'--------------------------------------------------------------
' This code is automatically generated by the button wizard.
' The lines with an apostroph at the beginning may be deleted.
' (see step 5!)

'On Error GoTo Err_cmdSave_Click


    DoCmd.RunCommand acCmdSaveRecord

'Exit_cmdSave_Click:
'    Exit Sub
'
'Err_cmdSave_Click:
'    MsgBox Err.Description
'    Resume Exit_cmdSave_Click
    
End Sub

Private Sub lstEmployees_AfterUpdate()
'--------------------------------------------------------------
' This code is automatically generated by the list box wizard.
' It is executed every time, when another entity is selected
' in the list (="after update" of the list) - either by clicking
' with the mouse or by pressing the "up" key or the "down" key.
' Its objective is to display the data of that entity, that
' was selected in the list.
' The selected entity is found using its primary key!
' (see the line "rs.FindFirst ...")

' The code contains lots of terms, which need to be explained:
' ...........................................................
' A "recordset" is a temporary copy of data from the data base.
' It is used to find the entity, that was selected in the list.

' A "Clone" is an identical copy of a recordset.

' A "bookmark" is a pointer to a certain data record in the data base.
' It is used to navigate within the data base (if you "point to"
' data, they are dispalyed in the form!)

' "EOF"   is an abbrevation for "end-of-file".
'         (in this case it means "end of the recordset")
' "Str"   changes the number (primary key) into a string.
' "Nz"    sets the found number to zero (0), if the selected
'         entity was not found in the data base.
' "Me"    means the form itself ("Hi - it's me!")

Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[emp_id] = " & Str(Nz(Me![lstEmployees], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

End Sub


========================================================
Code of the form 'frmStart'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmStart"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database
Option Explicit

Private Sub button_auftragsbearbeitung_Click()
'--------------------------------------------------------------
DoCmd.OpenForm "frmOrderProcessing"
End Sub

Private Sub button_beenden_Click()
'--------------------------------------------------------------
If MsgBox("Do you really want to stop working and close Access?", _
          vbYesNo + vbDefaultButton2) = vbYes Then DoCmd.Quit
End Sub

Private Sub button_kunden_Click()
'--------------------------------------------------------------
DoCmd.OpenForm "frmCustomers"
End Sub

Private Sub button_kunden_falsch_Click()
'--------------------------------------------------------------
DoCmd.OpenForm "frmCustomers"
End Sub

Private Sub button_kundenauftraege_Click()
'--------------------------------------------------------------
DoCmd.OpenForm "frmOrders"
End Sub

Private Sub button_materialart_Click()
'--------------------------------------------------------------
DoCmd.OpenForm "frmMaterials"
End Sub

Private Sub button_mitarbeiter_Click()
'--------------------------------------------------------------
DoCmd.OpenForm "frmEmployees"
End Sub

Private Sub button_personalplanung_Click()
'--------------------------------------------------------------
DoCmd.OpenForm "frmHRplanning"
End Sub

Private Sub cmdAuftragsbearbeitung1_Click()
DoCmd.OpenForm "frmOrderProcessingAfterStep1"
End Sub

Private Sub cmdAuftragsbearbeitung2_Click()
DoCmd.OpenForm "frmOrderProcessingAfterStep2"
End Sub

Private Sub cmdAuftragsbearbeitung3_Click()
DoCmd.OpenForm "frmOrderProcessingAfterStep3"
End Sub

Private Sub cmdAuftragsbearbeitung4_Click()
DoCmd.OpenForm "frmOrderProcessingAfterStep4"
End Sub

Private Sub cmdAuftragsbearbeitung5_Click()
DoCmd.OpenForm "frmOrderProcessingAfterStep5"
End Sub

Private Sub cmdAuftragsbearbeitung6_Click()
DoCmd.OpenForm "frmOrderProcessingAfterStep6"
End Sub

Private Sub cmdAuftragsbearbeitung7_Click()
DoCmd.OpenForm "frmOrderProcessingAfterStep7"
End Sub

Private Sub cmdKunden1_Click()
DoCmd.OpenForm "frmCustomersAfterStep1"
End Sub

Private Sub cmdKunden2_Click()
DoCmd.OpenForm "frmCustomersAfterStep2"
End Sub

Private Sub cmdKunden3_Click()
DoCmd.OpenForm "frmCustomersAfterStep3"
End Sub

Private Sub cmdKunden4_Click()
DoCmd.OpenForm "frmCustomersAfterStep4"
End Sub

Private Sub cmdKunden5_Click()
DoCmd.OpenForm "frmCustomersAfterStep5"
End Sub

Private Sub cmdKunden6_Click()
DoCmd.OpenForm "frmCustomersAfterStep6"
End Sub

Private Sub cmdKunden7_Click()
DoCmd.OpenForm "frmCustomersAfterStep7"
End Sub

Private Sub cmdKundenauftraege1_Click()
DoCmd.OpenForm "frmOrders1"
End Sub

Private Sub cmdKundenauftraege2_Click()
DoCmd.OpenForm "frmOrders2"
End Sub

Private Sub cmdKundenauftraege3_Click()
DoCmd.OpenForm "frmOrders3"
End Sub

Private Sub cmdKundenauftraege4_Click()
DoCmd.OpenForm "frmOrders4"
End Sub

Private Sub cmdKundenauftraege5_Click()
DoCmd.OpenForm "frmOrders5"
End Sub

Private Sub cmdKundenauftraege6_Click()
DoCmd.OpenForm "frmOrders6"
End Sub

Private Sub cmdKundenauftraege7_Click()
DoCmd.OpenForm "frmOrders7"
End Sub

Private Sub cmdMitarbeiter1_Click()
DoCmd.OpenForm "frmEmployeesAfterStep1"
End Sub

Private Sub cmdMitarbeiter2_Click()
DoCmd.OpenForm "frmEmployeesAfterStep2"
End Sub

Private Sub cmdMitarbeiter3_Click()
DoCmd.OpenForm "frmEmployeesAfterStep3"
End Sub

Private Sub cmdMitarbeiter4_Click()
DoCmd.OpenForm "frmEmployeesAfterStep4"
End Sub

Private Sub cmdMitarbeiter5_Click()
DoCmd.OpenForm "frmEmployeesAfterStep5"
End Sub

Private Sub cmdMitarbeiter6_Click()
DoCmd.OpenForm "frmEmployeesAfterStep6"
End Sub

Private Sub cmdMitarbeiter7_Click()
DoCmd.OpenForm "frmEmployeesAfterStep7"
End Sub

Private Sub Form_Open(Cancel As Integer)
'--------------------------------------------------------------
Dim rs As DAO.Recordset

' Get the version number from the table tblDBINFO

Set rs = CurrentDb.OpenRecordset("tblDBINFO", dbOpenDynaset)
rs.FindFirst "dbi_name='version'"

If rs.NoMatch Then
  Me!lblVersion2.Caption = ""
Else
  Me!lblVersion2.Caption = rs!dbi_wert
End If

End Sub


========================================================
Code of the form 'frmEmployeesAfterStep5'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmEmployeesAfterStep5"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database
Option Explicit

Private Sub cmdClose_Click()
'--------------------------------------------------------------
' Close the form

DoCmd.Close

End Sub

Private Sub cmdDelete_Click()
'--------------------------------------------------------------
' Attention: The needless code from step 4 was deleted!

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord

End Sub

Private Sub cmdNew_Click()
'--------------------------------------------------------------
' Attention: The needless code from step 4 was deleted!

DoCmd.GoToRecord , , acNewRec

End Sub

Private Sub cmdSave_Click()
'--------------------------------------------------------------
' Attention: The needless code from step 4 was deleted!

DoCmd.RunCommand acCmdSaveRecord

End Sub

Private Sub lstEmployees_AfterUpdate()
'--------------------------------------------------------------
' This code is automatically generated by the list box wizard.
' It is executed every time, when another entity is selected
' in the list (="after update" of the list) - either by clicking
' with the mouse or by pressing the "up" key or the "down" key.
' Its objective is to display the data of that entity, that
' was selected in the list.
' The selected entity is found using its primary key!
' (see the line "rs.FindFirst ...")

' The code contains lots of terms, which need to be explained:
' ...........................................................
' A "recordset" is a temporary copy of data from the data base.
' It is used to find the entity, that was selected in the list.

' A "Clone" is an identical copy of a recordset.

' A "bookmark" is a pointer to a certain data record in the data base.
' It is used to navigate within the data base (if you "point to"
' data, they are dispalyed in the form!)

' "EOF"   is an abbrevation for "end-of-file".
'         (in this case it means "end of the recordset")
' "Str"   changes the number (primary key) into a string.
' "Nz"    sets the found number to zero (0), if the selected
'         entity was not found in the data base.
' "Me"    means the form itself ("Hi - it's me!")

Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[emp_id] = " & Str(Nz(Me![lstEmployees], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

End Sub

========================================================
Code of the form 'frmCustomers'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmCustomers"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Option Compare Database

' ATTENTION!!
'=================================================================
' In this final version of the form some more code has been added
' in addition to the code, that was automatically generated by the
' wizards. It makes the application more professional.
' Please read the explanations in the code carefully!
'=================================================================

Private Sub cmdPrintAll_Click()
'--------------------------------------------------------------
' Print the data of all employees.
' The printing is not executed immediately. First a preview is shown.

DoCmd.OpenReport "rptCustomer", acViewPreview
End Sub

Private Sub cmdPrintOne_Click()
'--------------------------------------------------------------
' Print the data of the customer, that is selected in the list.
' (This is defined by its primary key "cus_id"!)

' Has the user selected a customer from the list?

If IsNull(lstCustomers) Then
   MsgBox "Please select a customer from the list!"
   Exit Sub
End If

' "Me" means the form itself ("Hi - it's me!")
' The printing is not executed immediately. First a preview is shown.

DoCmd.OpenReport "rptCustomer", acViewPreview, , "cus_id=" & Me!cus_id

End Sub

Private Sub cmdHelp_Click()
'--------------------------------------------------------------
' Show the form with the help information
' "customers" is the argument, that appears as "OpenArgs" in
' Form_Open in frmHelp! It is used to say the form frmHelp, which
' help information shall be shown.

DoCmd.OpenForm "frmHelp", , , , , , "customers"

End Sub

Private Sub cmdDelete_Click()
'--------------------------------------------------------------
' Delete one customer

' Definition of variables

Dim lngAnswer As Long     ' Type "Long integer"
Dim strMsgtext As String  ' Type "String"

' Has the user selected one customer in the list?

If IsNull(lstCustomers) Then
   MsgBox "Please select a customer in the list!"
   lstCustomers.SetFocus
   Exit Sub
End If

' The following code demonstrates one possibility to find out,
' if there are references to the entity to be deleted in other tables.

' Attention: The code in cmdDelete_Click in module frmMaterials demonstrates
'            another possibility to find out, if there are references to
'            the entity to be deleted in other tables!

' If there are still orders from the customer, that shall be deleted,
' it is not possible to delete him, because otherwise, there would be
' foreign keys cus_id_f in tblOrder which do not exist in the
' primary key column cus_id of the table tblCustomer.
' (-> violation of the referential integrity!)

' DCount("ord_id", "tblOrder", "cus_id_f=" & CStr(Me!cus_id)) means:
' Count the number of entries in the column "ord_id" of the table
' "tblOrder" for which the value in column "cus_id_f" is equal to
' the primary key of the customer displayed in this form (="Me!cus_id")
' = "How many orders are there of the current customer?"


If DCount("ord_id", "tblOrder", "cus_id_f=" & CStr(Me!cus_id)) > 0 Then
   MsgBox "The customer can not be deleted. There are still orders of him!"
   Exit Sub
End If

' Safety question
' Attention: By default, the second button ("No") of the corresponding
' message window is activated. That means: If the user only presses
' the "Enter" key, the delete command is NOT executed!

strMsgtext = "Do you really want to delete the customer " & Me!txtFirstName & " " & Me!txtLastName & "?"
lngAnswer = MsgBox(strMsgtext, vbYesNo + vbDefaultButton2)

' Execute the delete
' ....................
' Before the entity can be deleted from the table , all references to it
' in other tables must be deleted.

' In this case the entries in tblContact must be deleted, before the
' customer itself can be deleted.

If lngAnswer = vbYes Then  ' If the user has answered the safety question with "Yes" ...

   ' Delete the contacts of the customer and then ...
   CurrentDb.Execute "DELETE FROM tblContact WHERE cus_id_f=" & CStr(Me!cus_id)
   ' ... delete the customer itself
   CurrentDb.Execute "DELETE FROM tblCustomer WHERE cus_id=" & CStr(Me!cus_id)
   lstCustomers.Requery   ' Refresh the list (=the deleted entity disappears)
   Requery                ' Refresh the form
   lstCustomers.SetFocus
   
   ' Activate the first line of the list ("ItemData(0)") and
   ' show the data of that entity
   
   If Nz(lstCustomers.ListCount) > 0 Then
      Me!lstCustomers = Me!lstCustomers.ItemData(0)
      Call lstCustomers_AfterUpdate
   End If

End If

End Sub

Private Sub cmdNew_Click()
'--------------------------------------------------------------
' Add a new customer

' No line shall be selected in the list

lstCustomers = Null

' Create a new data record

DoCmd.GoToRecord , , acNewRec

' The user can immediately start typing, because the text marker
' is placed in the text box txtLastName

txtLastName.SetFocus

' If the user wants to enter a new entity, it makes no sense to
' start another action immediately after clicking on "new".
' Therefore all the other buttons are disabled.
' They are enabled again after the user has clicked "save"!

cmdNew.Enabled = False
cmdDelete.Enabled = False
lstCustomers.Enabled = False
cmdPrintOne.Enabled = False
cmdPrintAll.Enabled = False

End Sub

Private Sub cmdClose_Click()
'--------------------------------------------------------------
' Close the form

DoCmd.Close

End Sub

Private Sub cmdSave_Click()
'--------------------------------------------------------------
' Save the data to the data base

Dim lngCusId As Long

' Has the user entered at least a last name?

If Nz(txtLastName) = "" Then
   MsgBox "Please enter a customer name!"
   txtLastName.SetFocus
   Exit Sub
End If

' Save command

DoCmd.RunCommand (acCmdSaveRecord)

' The primary key of the saved entity is stored in a variable.
' This is used to activate the saved entity in the list.
' Otherwise after "Requery" the first entity of the list
' is activated. This would confuse the user, because the
' data displayed in the form are not the data of the entity
' that is selected in the list.

lngCusId = Me!cus_id

' Refresh the list
' (the FIRST entry of the list is activated now!)

lstCustomers.Enabled = True
lstCustomers.Requery

' Activate the just saved entity in the list again ...

lstCustomers.SetFocus
lstCustomers = lngCusId

' ... and show its data in the form.

Call lstCustomers_AfterUpdate

End Sub

Private Sub cmdStartform_Click()
'--------------------------------------------------------------
DoCmd.OpenForm "frmStart"
End Sub

Private Sub Form_Open(Cancel As Integer)
'--------------------------------------------------------------
' This form may be opend
'  -  either directly by a click in the start form or on the ribbon
'  -  or "indirectly" by a double click from "another" form.

' In that case, the entity, that was double clicked in the other form
' shall be displayed here - instead of the first entry from the list,
' which is displayed, if the form is simply opend from the start form or
' from the ribbon.

' The primary key of the double clicked entity is sent from the other
' form to this form via a variable called "OpenArgs" (=opening arguments).
' Which form that was, doesn't matter. The code works for any other form,
' that sends an "OpenArgs".

 ' To check this, have a look to the procedure
 ' txtName_DblClick in the form frmHRplanning1

Me!lstCustomers.SetFocus

If IsNull(OpenArgs) Then   ' The form was opend from the start form
                           ' or from the ribbon because OpenArgs is empty

   ' Activate the first line of the list and show the data of that
   ' entity in the form.

   If Nz(lstCustomers.ListCount) > 0 Then   ' erste Zeile anzeigen
      Me!lstCustomers = Me!lstCustomers.ItemData(0)
      Call lstCustomers_AfterUpdate
   End If

Else                       ' The form was opend by a double click
                           ' in another form because OpenArgs is NOT empty

   ' Activate that line of the list, that contains the entity,
   ' that was double clicked in the other form.
   ' (The entity to be activated is identified by its primary key,
   '  which is sent via OpenArgs!)
   
   Me!lstCustomers = OpenArgs
   Call lstCustomers_AfterUpdate
   
End If

' Enable all controls

cmdNew.Enabled = True
cmdSave.Enabled = True
cmdDelete.Enabled = True
lstCustomers.Enabled = True
cmdPrintOne.Enabled = True
cmdPrintAll.Enabled = True

' You can use the tab-key to move the input marker from box to box.
' The following command defines, what should happen, if you press
' the tab-key in the last box on the form.
' "1" means: "Jump back to the first box on the form!"

Me.Cycle = 1

End Sub

Private Sub lstCustomers_AfterUpdate()
'--------------------------------------------------------------
' Show the data of that entity, that was selected in the list, in the form

' The following line of code was a bit "compressed" in comparison to
' the code, that was automatically generated by the list box wizard.
' (see step 7)

' The following line of code means:
' If the list lstCustomers is not emtpy ("Not IsNull"), then ...
' ... search within the recordset (=the data source) of the current form ("Me")
' for the first value of "cus_id" (=the primary key in tblCustomer) that is equal
' to that one, that is selceted in the list box lstCustomers ("Me!lstCustomers")
' and display its data in the text boxes of the form.

If Not IsNull(lstCustomers) Then Me.Recordset.FindFirst "cus_id=" & Me!lstCustomers

' Enable the buttons, which may have been disabled before

cmdDelete.Enabled = True
cmdNew.Enabled = True
cmdPrintOne.Enabled = True
cmdPrintAll.Enabled = True

End Sub

Private Sub txtLastName_BeforeUpdate(Cancel As Integer)
'--------------------------------------------------------------
' The following code is very short, but needs a lot of explanation.
' Well - let's start:

' The storage of data in the data base may not only be executed with
' the command "DoCmd.RunCommand (acCmdSaveRecord)" which you know
' from the procedure cmdSave_Click. This is only the "explicit" method,
' which is executed by the user, who clicks on the "save" button.

' There is also an "implicit" storage method. It is executed, when
' you have entered data into a table (using the text boxes in a form)
' and then switch to another data record (by clicking into the list box).
' Access then assumes, that you are ready with editing the data
' and stores them.
' BUT: If the user has not yet entered all the necessary data,
'      this implicit storage must be prohibitet!
' This is done by this procedure.
' It is executed automatically by Access "before update", that means,
' before the storage (may be explicit / may be implicit!!) is executed.
' You can prohibit the execution of the storage by setting the argument
' "Cancel" to "True".

' Exactly that is done with the following code: If the user hasn't entered a
' last name (=necessary data!), the storage is prohibited!
' That's all.

If Nz(Me!txtLastName) = "" Then
   MsgBox "Please enter a name or press the Esc-key!"
   Cancel = True
End If

End Sub

========================================================
Code of the form 'frmCustomersAfterStep3'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmCustomersAfterStep3"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database
Option Explicit

Private Sub lstCustomers_AfterUpdate()
'--------------------------------------------------------------
' This code is automatically generated by the list box wizard.
' It is executed every time, when another entity is selected
' in the list (="after update" of the list) - either by clicking
' with the mouse or by pressing the "up" key or the "down" key.
' Its objective is to display the data of that entity, that
' was selected in the list.
' The selected entity is found using its primary key!
' (see the line "rs.FindFirst ...")

' The code contains lots of terms, which need to be explained:
' ...........................................................
' A "recordset" is a temporary copy of data from the data base.
' It is used to find the entity, that was selected in the list.

' A "Clone" is an identical copy of a recordset.

' A "bookmark" is a pointer to a certain data record in the data base.
' It is used to navigate within the data base (if you "point to"
' data, they are dispalyed in the form!)

' "EOF"   is an abbrevation for "end-of-file".
'         (in this case it means "end of the recordset")
' "Str"   changes the number (primary key) into a string.
' "Nz"    sets the found number to zero (0), if the selected
'         entity was not found in the data base.
' "Me"    means the form itself ("Hi - it's me!")

Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[cus_id] = " & Str(Nz(Me![lstCustomers], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

End Sub


========================================================
Code of the form 'frmEmployeesAfterStep6'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmEmployeesAfterStep6"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database
Option Explicit

Private Sub cmdClose_Click()
'--------------------------------------------------------------
' Close the form

DoCmd.Close

End Sub

Private Sub cmdDelete_Click()
'--------------------------------------------------------------

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord

' Attention:
' ..........
' The following line must be added to the automatically generated code.
' Otherwise the deleted employee doesn't disappear from the list.

lstEmployees.Requery

End Sub

Private Sub cmdNew_Click()
'--------------------------------------------------------------

DoCmd.GoToRecord , , acNewRec

End Sub

Private Sub cmdSave_Click()
'--------------------------------------------------------------

DoCmd.RunCommand acCmdSaveRecord

' Attention:
' ..........
' The following line must be added to the automatically generated code.
' Otherwise a newly generated employee doesn't appear in the list.

lstEmployees.Requery

End Sub

Private Sub lstEmployees_AfterUpdate()
'--------------------------------------------------------------
' This code is automatically generated by the list box wizard.
' It is executed every time, when another entity is selected
' in the list (="after update" of the list) - either by clicking
' with the mouse or by pressing the "up" key or the "down" key.
' Its objective is to display the data of that entity, that
' was selected in the list.
' The selected entity is found using its primary key!
' (see the line "rs.FindFirst ...")

' The code contains lots of terms, which need to be explained:
' ...........................................................
' A "recordset" is a temporary copy of data from the data base.
' It is used to find the entity, that was selected in the list.

' A "Clone" is an identical copy of a recordset.

' A "bookmark" is a pointer to a certain data record in the data base.
' It is used to navigate within the data base (if you "point to"
' data, they are dispalyed in the form!)

' "EOF"   is an abbrevation for "end-of-file".
'         (in this case it means "end of the recordset")
' "Str"   changes the number (primary key) into a string.
' "Nz"    sets the found number to zero (0), if the selected
'         entity was not found in the data base.
' "Me"    means the form itself ("Hi - it's me!")

Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[emp_id] = " & Str(Nz(Me![lstEmployees], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

End Sub


========================================================
Code of the form 'frmOrderProcessing_sfmMaterials'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmOrderProcessing_sfmMaterials"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database
Option Explicit

' ===============================================================
' Sorry ...
' ... the comments are not yet completely translated into English
' ===============================================================

Private Sub cboMaterial_AfterUpdate()
'--------------------------------------------------------------
' Durch die nderung des Wertes in einem Kombinationsfeld wird eine
' Transaktion (nderung von Daten in der Datenbank) begonnen
' (erkennbar am Schreibstift im Datensatzmarkierer!).
' Da eine nicht ordnungsgem beendete Transaktion zu Fehlern fhren kann,
' wird die gerade begonnene Transaktion auch sofort wieder durch einen
' "Speichern"-Befehl beendet.

DoCmd.RunCommand (acCmdSaveRecord)

End Sub

Private Sub cboMaterial_Dirty(Cancel As Integer)
'--------------------------------------------------------------
' Als Schutz gegen ein versehentliches ndern des Wertes im Kombinationsfeld
' wird gefragt, ob der Wert wirklich gendert werden soll.
' (Bei der allerersten Eingabe eines Wertes wird nicht gefragt).

If IsNull(cboMaterial.OldValue) Then Exit Sub
If MsgBox("Do you really want to change the material?", _
           vbYesNo + vbDefaultButton2) = vbNo Then Cancel = True

End Sub

Private Sub cboMaterial_GotFocus()
'--------------------------------------------------------------
' Sicherheitsmanahme: Falls der Inhalt des Kombinationsfedles in einem ANDREREN Formular
'                      gendert wurde, muss es hier aktualisiert werden.
cboMaterial.Requery

End Sub

Private Sub cmdDelete_Click()
Dim strMsgtext As String
Dim lngAnswer As Long
Dim strSQL As String

'In der letzten Zeile kann ein neuer Datensatz eingegeben werden.
'Dort darf nicht gelscht werden.

If IsNull(cboMaterial) Then Exit Sub

'Sicherheitsfrage

strMsgtext = "Do you really want to delete the material" & vbCrLf & _
           cboMaterial.Column(1) & "?"
lngAnswer = MsgBox(strMsgtext, vbYesNo + vbDefaultButton2)
If lngAnswer = vbNo Then Exit Sub

strSQL = "DELETE FROM tblMat_Ord WHERE mat_id_f=" & CStr(Me!cboMaterial) & _
          " AND ord_id_f=" & CStr(Parent!ord_id)
'MsgBox strSQL
'Exit Sub
CurrentDb.Execute strSQL
Requery

End Sub


Private Sub Form_Open(Cancel As Integer)
' You can use the tab-key to move the input marker from box to box.
' The following command defines, what should happen, if you press
' the tab-key in the last box on the form.
' "1" means: "Jump back to the first box on the form!"

Me.Cycle = 1
End Sub

========================================================
Code of the form 'frmZZFillColumns'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmZZfillColumns"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database
Option Explicit

' ===============================================================
' Sorry ...
' ... the comments are not yet completely translated into English
' ===============================================================

Private Sub cmdStart_Click()
Dim lngCurrentId As Long
Dim lngNrOfRows As Long
Dim lngLastId As Long
Dim strSQL As String
Dim rs As DAO.Recordset
Dim tdef As TableDef
Dim booFound As Boolean
Dim fldColumn As Field

lblReady.Visible = False

If Nz(txtInTable) = "" Then
   MsgBox "Please enter the name of the target table!"
   txtInTable.SetFocus
   Exit Sub
End If

If Nz(txtInColumn) = "" Then
   MsgBox "Please enter the name of the target column!"
   txtInColumn.SetFocus
   Exit Sub
End If

' Existiert die Zieltabelle?

booFound = False
For Each tdef In CurrentDb.TableDefs
   If tdef.Name = txtInTable Then
      booFound = True
      Exit For
   End If
Next tdef

If Not booFound Then
   MsgBox "There is no table with the name " & txtInTable & "!"
   DoCmd.Hourglass False
   txtInTable.SetFocus
   Exit Sub
End If

' Existiert die Zielspalte?

booFound = False
For Each fldColumn In tdef.Fields
   If fldColumn.Name = txtInColumn Then booFound = True
Next fldColumn

If Not booFound Then
   MsgBox "In the table " & txtInTable & _
          " there is no column with the name " & txtInColumn & "!"
   DoCmd.Hourglass False
   txtInColumn.SetFocus
   Exit Sub
End If

' Das knnte lange dauern - darum Anzeige der Sanduhr

DoCmd.Hourglass True

' Wieviele Zeilen hat die Tabelle tblFilltext?

lngNrOfRows = Nz(DCount("fill_id", "tblFilltext"))
lngLastId = DMax("fill_id", "tblFilltext")

If lngNrOfRows = 0 Then
   MsgBox "The table tblFilltext is empty!"
   Exit Sub
End If

' Nummer der Zeile der Tabelle tblFuelltext, in der begonnen werden soll
' (standardmig die erste - man kann aber auch irgendwo anders beginnen)

lngCurrentId = DMin("fill_id", "tblFilltext")

' Trick17: Die Spalte, in die die Daten HINEIN sollen, bekommt
' den Aliasnamen "fuellspalte". Darum braucht man sich nachher beim Fllen
' nicht mehr um den konkreten Namen der Spalte zu kmmern und kann
' einfach schreiben "rs!fuellspalte"

strSQL = "SELECT " & txtInColumn & " AS fuellspalte FROM " & txtInTable

' Jeweils EINEN Flltext in jede zu fllende Zelle

'Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
'Do Until rs.EOF
'   rs.Edit
'   rs!fuellspalte = DLookup("fill_text", "tblFilltext", "fill_id=" & Cstr(lngCurrentId))
'   rs.Update
'   lngCurrentId = lngCurrentId + 1   ' nchste Zeile in tblFuelltext
'   If lngCurrentId > lngLastId Then lngCurrentId = DMin("fill_id", "tblFilltext")   ' ggf. von vorne beginnen
'   rs.MoveNext
'Loop

' Jeweils ZWEI Flltexte in jede zu fllende Zelle

Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
Do Until rs.EOF
   rs.Edit
   rs!fuellspalte = DLookup("fill_text", "tblFilltext", "fill_id=" & CStr(lngCurrentId))
   lngCurrentId = lngCurrentId + 1                                                  ' nchste Zeile in tblFilltext
   If lngCurrentId > lngLastId Then lngCurrentId = DMin("fill_id", "tblFilltext")   ' ggf. von vorne beginnen
   rs!fuellspalte = rs!fuellspalte & vbCrLf & _
                    DLookup("fill_text", "tblFilltext", "fill_id=" & CStr(lngCurrentId))
   rs.Update
   lngCurrentId = lngCurrentId + 1                                                        ' nchste Zeile in tblFilltext
   If lngCurrentId > lngLastId Then lngCurrentId = DMin("fill_id", "tblFilltext")   ' ggf. von vorne beginnen
   rs.MoveNext
Loop


rs.Close
Set rs = Nothing

DoCmd.Hourglass False
lblReady.Visible = True

End Sub

Private Sub Form_Open(Cancel As Integer)
txtInTable.SetFocus
lblReady.Visible = False
End Sub

Private Sub txtInColumn_Change()
lblReady.Visible = False
End Sub

Private Sub txtInTable_Change()
lblReady.Visible = False
End Sub

Private Sub txtFromColumn_Change()
lblReady.Visible = False
End Sub

Private Sub txtFromTable_Change()
lblReady.Visible = False
End Sub

========================================================
Code of the form 'frmCustomersAfterStep4'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmCustomersAfterStep4"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database
Option Explicit

Private Sub cmdClose_Click()
'--------------------------------------------------------------
' Close the form

DoCmd.Close

End Sub

Private Sub cmdDelete_Click()
'--------------------------------------------------------------
' This code is automatically generated by the button wizard.
' The lines with an apostroph at the beginning may be deleted.
' (see step 5!)

'On Error GoTo Err_cmdDelete_Click


    DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdDeleteRecord

'Exit_cmdDelete_Click:
'    Exit Sub

'Err_cmdDelete_Click:
'    MsgBox Err.Description
'    Resume Exit_cmdDelete_Click

End Sub

Private Sub cmdNew_Click()
'--------------------------------------------------------------
' This code is automatically generated by the button wizard.
' The lines with an apostroph at the beginning may be deleted.
' (see step 5!)

'On Error GoTo Err_cmdNew_Click


    DoCmd.GoToRecord , , acNewRec

'Exit_cmdNew_Click:
'    Exit Sub
'
'Err_cmdNew_Click:
'    MsgBox Err.Description
'    Resume Exit_cmdNew_Click
    
End Sub

Private Sub cmdSave_Click()
'--------------------------------------------------------------
' This code is automatically generated by the button wizard.
' The lines with an apostroph at the beginning may be deleted.
' (see step 5!)

'On Error GoTo Err_cmdSave_Click


    DoCmd.RunCommand acCmdSaveRecord

'Exit_cmdSave_Click:
'    Exit Sub
'
'Err_cmdSave_Click:
'    MsgBox Err.Description
'    Resume Exit_cmdSave_Click
    
End Sub

Private Sub lstCustomers_AfterUpdate()
'--------------------------------------------------------------
' This code is automatically generated by the list box wizard.
' It is executed every time, when another entity is selected
' in the list (="after update" of the list) - either by clicking
' with the mouse or by pressing the "up" key or the "down" key.
' Its objective is to display the data of that entity, that
' was selected in the list.
' The selected entity is found using its primary key!
' (see the line "rs.FindFirst ...")

' The code contains lots of terms, which need to be explained:
' ...........................................................
' A "recordset" is a temporary copy of data from the data base.
' It is used to find the entity, that was selected in the list.

' A "Clone" is an identical copy of a recordset.

' A "bookmark" is a pointer to a certain data record in the data base.
' It is used to navigate within the data base (if you "point to"
' data, they are dispalyed in the form!)

' "EOF"   is an abbrevation for "end-of-file".
'         (in this case it means "end of the recordset")
' "Str"   changes the number (primary key) into a string.
' "Nz"    sets the found number to zero (0), if the selected
'         entity was not found in the data base.
' "Me"    means the form itself ("Hi - it's me!")

Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[cus_id] = " & Str(Nz(Me![lstCustomers], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

End Sub


========================================================
Code of the form 'frmEmployeesAfterStep7'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmEmployeesAfterStep7"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Option Compare Database

Private Sub cmdClose_Click()
'--------------------------------------------------------------
' Close the form

DoCmd.Close

End Sub

Private Sub cmdDelete_Click()
'--------------------------------------------------------------

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord

' Attention:
' ..........
' The following line must be added to the automatically generated code.
' Otherwise the deleted employee doesn't disappear from the list.

lstEmployees.Requery

End Sub

Private Sub cmdNew_Click()
'--------------------------------------------------------------

DoCmd.GoToRecord , , acNewRec

End Sub

Private Sub cmdSave_Click()
'--------------------------------------------------------------

DoCmd.RunCommand acCmdSaveRecord

' Attention:
' ..........
' The following line must be added to the automatically generated code.
' Otherwise a newly generated employee doesn't appear in the list.

lstEmployees.Requery

End Sub

Private Sub lstEmployees_AfterUpdate()
'--------------------------------------------------------------
' This code is automatically generated by the list box wizard.
' It is executed every time, when another entity is selected
' in the list (="after update" of the list) - either by clicking
' with the mouse or by pressing the "up" key or the "down" key.
' Its objective is to display the data of that entity, that
' was selected in the list.
' The selected entity is found using its primary key!
' (see the line "rs.FindFirst ...")

' The code contains lots of terms, which need to be explained:
' ...........................................................
' A "recordset" is a temporary copy of data from the data base.
' It is used to find the entity, that was selected in the list.

' A "Clone" is an identical copy of a recordset.

' A "bookmark" is a pointer to a certain data record in the data base.
' It is used to navigate within the data base (if you "point to"
' data, they are dispalyed in the form!)

' "EOF"   is an abbrevation for "end-of-file".
'         (in this case it means "end of the recordset")
' "Str"   changes the number (primary key) into a string.
' "Nz"    sets the found number to zero (0), if the selected
'         entity was not found in the data base.
' "Me"    means the form itself ("Hi - it's me!")

Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[emp_id] = " & Str(Nz(Me![lstEmployees], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

End Sub


========================================================
Code of the form 'frmFirstStart'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmFirstStart"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database
Option Explicit

Private Sub cmdClose_Click()
'--------------------------------------------------------------

Select Case chkDisplay
Case 0   ' Show the form
   
   CurrentDb.Execute "UPDATE tblDBINFO SET dbi_wert='yes' WHERE dbi_name='first_start'"

Case -1   ' Hide the form
   
   CurrentDb.Execute "UPDATE tblDBINFO SET dbi_wert='no' WHERE dbi_name='first_start'"

End Select

DoCmd.Close
End Sub

Private Sub Form_Open(Cancel As Integer)
'--------------------------------------------------------------

If DLookup("dbi_wert", "tblDBINFO", "dbi_name='first_start'") = "no" Then
   Cancel = True
End If

End Sub

========================================================
Code of the form 'frmCustomersAfterStep5'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmCustomersAfterStep5"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database
Option Explicit

Private Sub cmdClose_Click()
'--------------------------------------------------------------
' Close the form

DoCmd.Close

End Sub

Private Sub cmdDelete_Click()
'--------------------------------------------------------------
' This code is automatically generated by the button wizard.
' The lines with an apostroph at the beginning may be deleted.
' (see step 5!)

'On Error GoTo Err_cmdDelete_Click


    DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdDeleteRecord

'Exit_cmdDelete_Click:
'    Exit Sub

'Err_cmdDelete_Click:
'    MsgBox Err.Description
'    Resume Exit_cmdDelete_Click

End Sub

Private Sub cmdNew_Click()
'--------------------------------------------------------------
' This code is automatically generated by the button wizard.
' The lines with an apostroph at the beginning may be deleted.
' (see step 5!)

'On Error GoTo Err_cmdNew_Click


    DoCmd.GoToRecord , , acNewRec

'Exit_cmdNew_Click:
'    Exit Sub
'
'Err_cmdNew_Click:
'    MsgBox Err.Description
'    Resume Exit_cmdNew_Click
    
End Sub

Private Sub cmdSave_Click()
'--------------------------------------------------------------
' This code is automatically generated by the button wizard.
' The lines with an apostroph at the beginning may be deleted.
' (see step 5!)

'On Error GoTo Err_cmdSave_Click


    DoCmd.RunCommand acCmdSaveRecord

'Exit_cmdSave_Click:
'    Exit Sub
'
'Err_cmdSave_Click:
'    MsgBox Err.Description
'    Resume Exit_cmdSave_Click
    
End Sub

Private Sub lstCustomers_AfterUpdate()
'--------------------------------------------------------------
' This code is automatically generated by the list box wizard.
' It is executed every time, when another entity is selected
' in the list (="after update" of the list) - either by clicking
' with the mouse or by pressing the "up" key or the "down" key.
' Its objective is to display the data of that entity, that
' was selected in the list.
' The selected entity is found using its primary key!
' (see the line "rs.FindFirst ...")

' The code contains lots of terms, which need to be explained:
' ...........................................................
' A "recordset" is a temporary copy of data from the data base.
' It is used to find the entity, that was selected in the list.

' A "Clone" is an identical copy of a recordset.

' A "bookmark" is a pointer to a certain data record in the data base.
' It is used to navigate within the data base (if you "point to"
' data, they are dispalyed in the form!)

' "EOF"   is an abbrevation for "end-of-file".
'         (in this case it means "end of the recordset")
' "Str"   changes the number (primary key) into a string.
' "Nz"    sets the found number to zero (0), if the selected
'         entity was not found in the data base.
' "Me"    means the form itself ("Hi - it's me!")

Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[cus_id] = " & Str(Nz(Me![lstCustomers], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

End Sub

========================================================
Code of the form 'frmCustomersAfterStep6'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmCustomersAfterStep6"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database
Option Explicit

Private Sub cmdClose_Click()
'--------------------------------------------------------------
' Close the form

DoCmd.Close

End Sub

Private Sub cmdDelete_Click()
'--------------------------------------------------------------

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord

' Attention:
' ..........
' The following line must be added to the automatically generated code.
' Otherwise the deleted employee doesn't disappear from the list.

lstCustomers.Requery

End Sub

Private Sub cmdNew_Click()
'--------------------------------------------------------------

DoCmd.GoToRecord , , acNewRec

End Sub

Private Sub cmdSave_Click()
'--------------------------------------------------------------

DoCmd.RunCommand acCmdSaveRecord

' Attention:
' ..........
' The following line must be added to the automatically generated code.
' Otherwise a newly generated employee doesn't appear in the list.

lstCustomers.Requery

End Sub

Private Sub lstCustomers_AfterUpdate()
'--------------------------------------------------------------
' This code is automatically generated by the list box wizard.
' It is executed every time, when another entity is selected
' in the list (="after update" of the list) - either by clicking
' with the mouse or by pressing the "up" key or the "down" key.
' Its objective is to display the data of that entity, that
' was selected in the list.
' The selected entity is found using its primary key!
' (see the line "rs.FindFirst ...")

' The code contains lots of terms, which need to be explained:
' ...........................................................
' A "recordset" is a temporary copy of data from the data base.
' It is used to find the entity, that was selected in the list.

' A "Clone" is an identical copy of a recordset.

' A "bookmark" is a pointer to a certain data record in the data base.
' It is used to navigate within the data base (if you "point to"
' data, they are dispalyed in the form!)

' "EOF"   is an abbrevation for "end-of-file".
'         (in this case it means "end of the recordset")
' "Str"   changes the number (primary key) into a string.
' "Nz"    sets the found number to zero (0), if the selected
'         entity was not found in the data base.
' "Me"    means the form itself ("Hi - it's me!")

Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[cus_id] = " & Str(Nz(Me![lstCustomers], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

End Sub



========================================================
Code of the form 'frmCustomersAfterStep7'
========================================================
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmCustomersAfterStep7"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database
Option Explicit

Private Sub cmdClose_Click()
'--------------------------------------------------------------
' Close the form

DoCmd.Close

End Sub

Private Sub cmdDelete_Click()
'--------------------------------------------------------------

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord

' Attention:
' ..........
' The following line must be added to the automatically generated code.
' Otherwise the deleted customer doesn't disappear from the list.

lstCustomers.Requery

End Sub

Private Sub cmdNew_Click()
'--------------------------------------------------------------

DoCmd.GoToRecord , , acNewRec

End Sub

Private Sub cmdSave_Click()
'--------------------------------------------------------------

DoCmd.RunCommand acCmdSaveRecord

' Attention:
' ..........
' The following line must be added to the automatically generated code.
' Otherwise a newly generated customer doesn't appear in the list.

lstCustomers.Requery

End Sub

Private Sub lstCustomers_AfterUpdate()
'--------------------------------------------------------------
' This code is automatically generated by the list box wizard.
' It is executed every time, when another entity is selected
' in the list (="after update" of the list) - either by clicking
' with the mouse or by pressing the "up" key or the "down" key.
' Its objective is to display the data of that entity, that
' was selected in the list.
' The selected entity is found using its primary key!
' (see the line "rs.FindFirst ...")

' The code contains lots of terms, which need to be explained:
' ...........................................................
' A "recordset" is a temporary copy of data from the data base.
' It is used to find the entity, that was selected in the list.

' A "Clone" is an identical copy of a recordset.

' A "bookmark" is a pointer to a certain data record in the data base.
' It is used to navigate within the data base (if you "point to"
' data, they are dispalyed in the form!)

' "EOF"   is an abbrevation for "end-of-file".
'         (in this case it means "end of the recordset")
' "Str"   changes the number (primary key) into a string.
' "Nz"    sets the found number to zero (0), if the selected
'         entity was not found in the data base.
' "Me"    means the form itself ("Hi - it's me!")

Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[cus_id] = " & Str(Nz(Me![lstCustomers], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

End Sub

**********************************************************************
**********************************************************************
Code of the module 'SupportProcedures'
**********************************************************************
**********************************************************************
Attribute VB_Name = "SupportProcedures"
Option Compare Database
Option Explicit

Public Function eigene_MFL_laden()
' Der Wert der Konstanten "Accessversion" wird so gesetzt:
' In VBA: Extras / Eigenschaften von ...
' Dort unter "Argumente fr die bedingte Kompilierung"
' Will man dort mehrere Konstanten definieren,
' so mssen sie durch Doppelpunkte voneinander getrennt werden!

#If Accessversion > 2003 Then
   Application.LoadCustomUI "Eigene_MFL", _
                            DLookup("mfl_code", "tblMFL", "mfl_name='eigene_MFL'")
#End If

End Function

#If Accessversion > 2003 Then

Sub OnButtonClick(control As IRibbonControl)
Select Case control.id

   Case "start"
      DoCmd.OpenForm "frmStart"

   Case "customers"
      DoCmd.OpenForm "frmCustomers"
   Case "orders"
      DoCmd.OpenForm "frmOrders"

   Case "orderprocessing"
      DoCmd.OpenForm "frmOrderProcessing"
   Case "hrplanning"
      DoCmd.OpenForm "frmHRplanning"

   Case "materials"
      DoCmd.OpenForm "frmMaterials"
   Case "employees"
      DoCmd.OpenForm "frmEmployees"

   Case Else
      MsgBox "OnButtonClick: Unknown form name!"

End Select
End Sub
#End If

Public Function errorhandling() As Boolean
errorhandling = False
End Function

Public Function FormIsOpen(formname As String) As Boolean
Dim objFrm As Form
FormIsOpen = False
For Each objFrm In Forms
   If objFrm.Name = formname Then FormIsOpen = True
Next objFrm
End Function

Public Sub asShowHelp(strObjectName As String)
'--------------------------------------------------------------
'Hilfe-Datei anzeigen

If errorhandling Then On Error GoTo fehlerbehandlung

Dim strFileName As String
Dim fso As Object

strFileName = Application.CurrentProject.Path & "\help-" & strObjectName

' In Access 2003 knnen Textboxen keine .rtf-Daten darstellen.
' Darum dort nur .txt-Dateien als Hilfedateien!

' Der Wert der Konstanten "Accessversion" wird so gesetzt:
' In VBA: Extras / Eigenschaften von ...
' Dort unter "Argumente fr die bedingte Kompilierung"
' Will man dort mehrere Konstanten definieren,
' so mssen sie durch Doppelpunkte voneinander getrennt werden!

#If Accessversion > 2003 Then
   strFileName = strFileName & ".rtf"
#Else
   strFileName = strFileName & ".txt"
#End If

Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(strFileName) Then
   DoCmd.OpenForm "frmHelp", , , , , , strFileName
Else
   MsgBox "Sorry - there is no help information for this form."
End If

Exit Sub
fehlerbehandlung:
   MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical

End Sub
