Stephenjames28
New Member
Hope I can get some help here!....I have created a Userform and I want to create a unique reference for each form when they open the form and when they click OK it puts the reference number in the cell. The currect VB coding I have at present is the following:
Can you help??
Steve
Code:
Private Sub cmdOK_Click()
Dim RowCount As Long
Dim ctl As Control
If Me.txtcustomer.Value = "" Then
MsgBox "Please enter a Customer Name.", vbExclamation, "Hellmann Issue log"
Me.txtcustomer.SetFocus
Exit Sub
End If
If Me.txtcoordinator.Value = "" Then
MsgBox "Please enter a Coordinator's Name.", vbExclamation, "Hellmann Issue log"
Me.txtcoordinator.SetFocus
Exit Sub
End If
If Not IsDate(Me.txtdate.Value) Then
MsgBox "The Date box must contain a date.", vbExclamation, "Hellmann Issue log"
Me.txtdate.SetFocus
Exit Sub
End If
If Me.txtissue.Value = "" Then
MsgBox "Please enter the issue", vbExclamation, "Hellmann Issue log"
Me.txtissue.SetFocus
Exit Sub
End If
If Me.txtconsequence.Value = "" Then
MsgBox "Please enter consequence", vbExclamation, "Hellmann Issue log"
Me.txtconsequence.SetFocus
Exit Sub
End If
If Me.cboimpact.Value = "" Then
MsgBox "Please select an impact value", vbExclamation, "Hellmann Issue log"
Me.cboimpact.SetFocus
Exit Sub
End If
If Me.txtrootcause.Value = "" Then
MsgBox "Please type the root cause issue", vbExclamation, "Hellmann Issue log"
Me.txtrootcause.SetFocus
Exit Sub
End If
If Me.cbostatus.Value = "" Then
MsgBox "Please select a status", vbExclamation, "Hellmann Issue log"
Me.cbostatus.SetFocus
Exit Sub
End If
RowCount = Worksheets("Sheet1").Range("A1").CurrentRegion.Rows.Count
With Worksheets("Sheet1").Range("A1")
.Offset(RowCount, 0).Value = Me.txtcustomer.Value
.Offset(RowCount, 1).Value = Me.txtcoordinator.Value
.Offset(RowCount, 2).Value = DateValue(Me.txtdate.Value)
.Offset(RowCount, 3).Value = Me.txtschoellerreference.Value
.Offset(RowCount, 4).Value = Me.txtissue.Value
.Offset(RowCount, 5).Value = Me.txtconsequence.Value
.Offset(RowCount, 6).Value = Me.cboimpact.Value
.Offset(RowCount, 7).Value = Me.txtrootcause.Value
.Offset(RowCount, 8).Value = Me.txtactionagreed.Value
.Offset(RowCount, 9).Value = Me.cbostatus.Value
.Offset(RowCount, 10).Value = Format(Now, "dd/mm/yyyy hh:nn:ss")
End With
For Each ctl In Me.Controls
If TypeName(ctl) = "TextBox" Or TypeName(ctl) = "ComboBox" Then
ctl.Value = ""
ElseIf TypeName(ctl) = "CheckBox" Then
ctl.Value = False
End If
Next ctl
End Sub
Can you help??
Steve
Last edited by a moderator: