Help Please
My form only shows information in the first few text boxes and the first text box (TxtBxPrimaryNo) shows the dated in stead of the information (just numbers) that it should show.
many thanks in advance.
Sub FormData(ByVal Form As Object, ByVal sh As Object, ByVal RecordRow As Long, ByVal Action As XLActionType)
Dim i As Integer
Dim CalDate As Variant
Dim msg As String
Dim ctrl As msforms.Control
On Error GoTo ExitSub
With sh
'add password if required
.Unprotect Password:=""
Select Case Action
Case xlNew
EnableButtons Form:=Form, NewButton:=False, CancelButton:=True, DeleteButton:=False, AddUpdateButton:="Add"
'
'Form.Calendar.Value = Date
'THERE IS NO CALANDER ON THIS FORM
'clear form
For Each ctrl In Form.Controls
If TypeName(ctrl) = "TextBox" Or TypeName(ctrl) = "ComboBox" Then ctrl.Value = ""
Next ctrl
Case xlAdd, xlUpdate
'validate required entry
For Each ctrl In Form.Controls
If Not IsComplete(ctrl) Then GoTo ExitSub
Next ctrl
For i = 0 To 50
If i = 0 Then
.Cells(RecordRow, 1).Offset(0, i).Value = Form.Controls(ControlArray(i)).Value
Else
.Cells(RecordRow, 1).Offset(0, i).Value = Form.Controls(ControlArray(i)).Value
End If
Next
EnableButtons Form
msg = IIf(Action = xlAdd, "New Record Added To Database", "Record Updated")
MsgBox msg, 48, Left(msg, 16)
Case xlScrollRow
For i = 0 To 50
If i = 0 Then
CalDate = .Cells(RecordRow, 1).Offset(0, i).Value
CalDate = IIf(IsDate(CalDate), CDate(CalDate), Date)
Form.Controls(ControlArray(i)).Value = CalDate
Else
Form.Controls(ControlArray(i)).Value = .Cells(RecordRow, 1).Offset(0, i).Value
End If
Next i
EnableButtons Form
Case xlDelete
Application.EnableEvents = False
.Cells(RecordRow, 1).EntireRow.Delete xlShiftUp
MsgBox "Record Deleted", 48, "Record Deleted"
End Select
'add password if required
'.Protect Password:=""
End With
ExitSub:
Application.EnableEvents = True
If Err > 0 Then MsgBox (Error(Err)), 48, "Error"
End Sub
Sub EnableButtons(ByVal Form As Object, Optional ByVal NewButton As Boolean = True, Optional ByVal CancelButton As Boolean, _
Optional ByVal DeleteButton As Boolean = True, Optional ByVal AddUpdateButton As String = "Update")
With Form
.ButtonCancel.Enabled = CancelButton
.ButtonNew.Enabled = NewButton
.ButtonDelete.Enabled = DeleteButton
.ButtonAddUpdate.Caption = AddUpdateButton
End With
End Sub
Function ControlArray() As Variant
ControlArray = Array("TxtBxPrimaryNo", "TxtBxModule", "TxtBxParentFler", _
"TxtbxFler", "TxtBxFlerDescription", "TxtBxAssetclass", "TxtBxCommdate", "TxtBxAssetRepVal", _
"TxtBxReliability", "TxtBxPerformance", "TxtBxExternalCondition", "TxtBxObsolescence", _
"TxtBxOverallCondition", "CmboBxFailuremode", "TxtBxFailureEffects", "TxtBxMTBF", "TxtBxAvgMainCost", _
"TxtBxProductionLossHrs", "TxtBxSafManHrs", "TxtBxRiskYear", "TxtBxUnplannedActual", _
"TxtBxPlannedActual", "TxtBxWk1", "TxtBxWeek2", "TxtBx1Mnth", "TxtBx2Mnth", "TxtBx3Mnth", "TxtBx6Mnth", _
"TxtBx1Y", "TxtBx2Yr", "TxtBx3Yr", "TxtBx4Yr", "TxtBox5Yr", "TxtBx7Yr", "TxtBx10Yr", "TxtBx12Yr", _
"TxtBx25Yr", "TxtBxParentWk1", "TxtBxParentWk2", "TxtBxParent1Mnth", "TxtBxParent2Mnth", "TxtParent3Mnth", _
"TxtBxParent6Mnth", "TxtBxParent1Yr", "TxtBxParent2Yr", "TxtBxParent3Yr", "TxtBxParent4Yr", "TxtBxParent5Yr", _
"TxtBxParent7Yr", "TxtBxParent10Yr", "TxtBxParent12y", "TxtBxParent25Yr", "CmboBxTaskStatus", _
"TxtBxMaintenanceComments", "TxtBxGeneralComments")
End Function
My form only shows information in the first few text boxes and the first text box (TxtBxPrimaryNo) shows the dated in stead of the information (just numbers) that it should show.
many thanks in advance.
Sub FormData(ByVal Form As Object, ByVal sh As Object, ByVal RecordRow As Long, ByVal Action As XLActionType)
Dim i As Integer
Dim CalDate As Variant
Dim msg As String
Dim ctrl As msforms.Control
On Error GoTo ExitSub
With sh
'add password if required
.Unprotect Password:=""
Select Case Action
Case xlNew
EnableButtons Form:=Form, NewButton:=False, CancelButton:=True, DeleteButton:=False, AddUpdateButton:="Add"
'
'Form.Calendar.Value = Date
'THERE IS NO CALANDER ON THIS FORM
'clear form
For Each ctrl In Form.Controls
If TypeName(ctrl) = "TextBox" Or TypeName(ctrl) = "ComboBox" Then ctrl.Value = ""
Next ctrl
Case xlAdd, xlUpdate
'validate required entry
For Each ctrl In Form.Controls
If Not IsComplete(ctrl) Then GoTo ExitSub
Next ctrl
For i = 0 To 50
If i = 0 Then
.Cells(RecordRow, 1).Offset(0, i).Value = Form.Controls(ControlArray(i)).Value
Else
.Cells(RecordRow, 1).Offset(0, i).Value = Form.Controls(ControlArray(i)).Value
End If
Next
EnableButtons Form
msg = IIf(Action = xlAdd, "New Record Added To Database", "Record Updated")
MsgBox msg, 48, Left(msg, 16)
Case xlScrollRow
For i = 0 To 50
If i = 0 Then
CalDate = .Cells(RecordRow, 1).Offset(0, i).Value
CalDate = IIf(IsDate(CalDate), CDate(CalDate), Date)
Form.Controls(ControlArray(i)).Value = CalDate
Else
Form.Controls(ControlArray(i)).Value = .Cells(RecordRow, 1).Offset(0, i).Value
End If
Next i
EnableButtons Form
Case xlDelete
Application.EnableEvents = False
.Cells(RecordRow, 1).EntireRow.Delete xlShiftUp
MsgBox "Record Deleted", 48, "Record Deleted"
End Select
'add password if required
'.Protect Password:=""
End With
ExitSub:
Application.EnableEvents = True
If Err > 0 Then MsgBox (Error(Err)), 48, "Error"
End Sub
Sub EnableButtons(ByVal Form As Object, Optional ByVal NewButton As Boolean = True, Optional ByVal CancelButton As Boolean, _
Optional ByVal DeleteButton As Boolean = True, Optional ByVal AddUpdateButton As String = "Update")
With Form
.ButtonCancel.Enabled = CancelButton
.ButtonNew.Enabled = NewButton
.ButtonDelete.Enabled = DeleteButton
.ButtonAddUpdate.Caption = AddUpdateButton
End With
End Sub
Function ControlArray() As Variant
ControlArray = Array("TxtBxPrimaryNo", "TxtBxModule", "TxtBxParentFler", _
"TxtbxFler", "TxtBxFlerDescription", "TxtBxAssetclass", "TxtBxCommdate", "TxtBxAssetRepVal", _
"TxtBxReliability", "TxtBxPerformance", "TxtBxExternalCondition", "TxtBxObsolescence", _
"TxtBxOverallCondition", "CmboBxFailuremode", "TxtBxFailureEffects", "TxtBxMTBF", "TxtBxAvgMainCost", _
"TxtBxProductionLossHrs", "TxtBxSafManHrs", "TxtBxRiskYear", "TxtBxUnplannedActual", _
"TxtBxPlannedActual", "TxtBxWk1", "TxtBxWeek2", "TxtBx1Mnth", "TxtBx2Mnth", "TxtBx3Mnth", "TxtBx6Mnth", _
"TxtBx1Y", "TxtBx2Yr", "TxtBx3Yr", "TxtBx4Yr", "TxtBox5Yr", "TxtBx7Yr", "TxtBx10Yr", "TxtBx12Yr", _
"TxtBx25Yr", "TxtBxParentWk1", "TxtBxParentWk2", "TxtBxParent1Mnth", "TxtBxParent2Mnth", "TxtParent3Mnth", _
"TxtBxParent6Mnth", "TxtBxParent1Yr", "TxtBxParent2Yr", "TxtBxParent3Yr", "TxtBxParent4Yr", "TxtBxParent5Yr", _
"TxtBxParent7Yr", "TxtBxParent10Yr", "TxtBxParent12y", "TxtBxParent25Yr", "CmboBxTaskStatus", _
"TxtBxMaintenanceComments", "TxtBxGeneralComments")
End Function