ToeShot, the code is as follows...it is long
The following is in the form "On Open Event". It simply sets up the form depending on how it will be used. I am not having any problems with adding to new or existing companies, only editing employees:
Private Sub Form_Open(pintCancel As Integer)
Call OpeningRoutine
End Sub
Private Sub OpeningRoutine()
'dim variables
Dim strFacilityNumber As String
Dim strNewAcctNo As String
Dim ctl As Control
'get facility number
strFacilityNumber = Forms!frmMoAcctCustEntry!cboFacilityNumber
'get HT or Key information;disable key field if HT
Set rst = New ADODB.Recordset
Set rst.ActiveConnection = CurrentProject.Connection
rst.Open "SELECT * FROM tblFacilityNumbers WHERE FacilityNumber = '" & strFacilityNumber & "'"
If rst!HangTagFlg Then txtCardNum.Enabled = False
rst.Close
Set rst = Nothing
Select Case Forms!frmMoAcctCustEntry!AddEditMode
Case Is = "AddNew"
'Code for adding to new accounts here
Case Is = "Add"
'Code for adding to existing accounts here
Case Is = "Edit"
Dim objPrkr As clsParker
Dim strKey As String
'set movement/entry controls
optInactive.Enabled = True
optHold.Enabled = True
cmdCloseFrm.Enabled = False
cmdPrkrUndo.Enabled = False
txtStartDate.Enabled = False
txtEndDate.Enabled = False
fraApplyDisc.Enabled = False
fraProRateFlg.Enabled = False
'set Facility number
Me!FacilityNumber.Value = strFacilityNumber
'Get the record for the selected employee
strKey = Forms!frmMoAcctCustEntry!subPrkrInfo!CardNum
If strKey <> "" Then
Set objPrkr = New clsParker
objPrkr.txtCardNum = Forms!frmMoAcctCustEntry!subPrkrInfo!CardNum
Else
Set objPrkr = New clsParker
objPrkr.txtPrkrNumber = Forms!frmMoAcctCustEntry!subPrkrInfo!txtPrkrNum
End If
If objPrkr.Load() Then
Call ScatterFields(objPrkr)
Set rst = New ADODB.Recordset
Set rst.ActiveConnection = CurrentProject.Connection
rst.Open "SELECT * FROM tblMoRateCodes WHERE FacilityNumber = '" & strFacilityNumber & "'" & _
"AND RateCode = '" & txtCode & "'"
txtRate.Value = rst!PublishedAmt
rst.Close
Set rst = Nothing
End If
'set the prorate field
ProrateMoYr.Value = Date
Case Else
Call MsgBox( " & vbCrLf & "Please select an Customer. ", _
vbOKOnly + vbInformation + vbDefaultButton1)
End Select
End Sub
The following is the code associated with the "Save" button after a change has been made on the customer form:
Private Sub cmdPrkrSave_Click()
cmdCloseFrm.Enabled = True
'Get info from form on which button was clicked
strMode = Forms!frmMoAcctCustEntry!AddEditMode
'Check if there is a name in the Employee field
If Me!txtPrkrLName = "" Then
MsgBox "Employee Name Required", vbExclamation
txtPrkrLName.SetFocus
Exit Sub
End If
'Check if type is selected
If IsNull(Me!cboType) Then
MsgBox "Type Required", vbExclamation
cboType.SetFocus
Exit Sub
End If
'Check for a key card number
If txtCardNum.Enabled = True Then
If fraPrkrStatus = 1 Then
If Me!txtCardNum = "" Then
MsgBox "Card Number Required", vbExclamation
txtCardNum.SetFocus
Exit Sub
End If
End If
End If
'Save the employee information
Call GatherFields(pObjPrkr)
Call pObjPrkr.Save
Forms!frmMoAcctCustEntry!TabCtl20.Pages![employee Information].Requery
'get/set facility number
strFacilityNumber = Forms!frmMoAcctCustEntry!cboFacilityNumber
Select Case strMode
Case Is = "AddNew"
'ADD employee during company input
Call AddNew
Case Is = "Add"
'ADD employee to existing company
Call Add
Case Is = "Edit"
'EDIT EXISTING employee
'Only Write prorate info to tblMoAdjDetails if there is a change in status
If fraProRateFlg = 1 Then
Set rst = New ADODB.Recordset
rst.ActiveConnection = CurrentProject.Connection
rst.Open "SELECT * FROM tblMoAdjDetails " & _
"WHERE FacilityNumber = '" & strFacilityNumber & "'", , adOpenKeyset, adLockOptimistic
With rst
.AddNew
!FacilityNumber = strFacilityNumber
!CoAcctNum = CustAcctNum
!PrkrNum = txtPrkrNumber
!PrkrName = txtPrkrLName
!PrkrCard = txtCardNum
!ManEmployeeName = Forms!frmMoAcctCustEntry!AcctName
!PrkrAdjExplanation = "1" 'Cancel employee
!PrkrAdjDate = txtStartDate
!Amt = txtProrateAmt
!SlsTaxAmt = pObjPrkr.ComputeSlsTax(txtProrateAmt, strFacilityNumber)
!PrkgTaxAmt = pObjPrkr.ComputePrkgTax(txtProrateAmt, strFacilityNumber)
If Forms!frmMoAcctCustEntry!IndvFlag Then
!WhenFlg = 1 'now
Else
Dim lngRetval As Long
lngRetval = MsgBox( "Would you like to invoice this Company Account now?", _
vbYesNo + vbInformation + vbDefaultButton1)
Select Case lngRetval
Case vbYes
!WhenFlg = 1 'now
Case vbNo
!WhenFlg = 2 ' next per
End Select
End If
!InvcdFlg = False
.Update
End With
rst.Close
Set rst = Nothing
End If
DoCmd.Close acForm, "frmMoPrkrInput"
End Select
End Sub