Hi Expert,
Just want to ask why my userform terminated after clicking the posted button.
This was haepen when after encoding the first transaction and posted to a temporary table the userform is terminated or unload.
It should be back to textbox2 where the the trasanction is not yet done for a certain ticket number.
Thank you.
here is my VBA macro code
Private Sub CmdPost_Click()
'Declare variable to check the answer
Dim x, I As Integer
Dim rw As Long ' Next available empty row
Set ws = Worksheets("TempTable")
'Validate combobox1
If CmbBoxDepartment.ListIndex = -1 Then
MsgBox "Missing or invalid Department. ", vbExclamation, "Invalid Department"
CmbBoxDepartment.SetFocus
Exit Sub
End If
If CmbBoxDescript.ListIndex = -1 Then
MsgBox "Missing or invalid Description. ", vbExclamation, "Invalid Description"
CmbBoxDescript.SetFocus
Exit Sub
End If
'Validate textboxes 1 to 8
For I = 1 To 8
With Me.Controls("TextBox" & I)
If Len(.Value) = 0 Then 'Or Not IsNumeric(.Value) Then
.SetFocus
MsgBox "Missing or You've not completed the value. ", vbExclamation, "Invalid Entry"
Exit Sub
End If
End With
Next I
'ask the question
x = MsgBox("Press Yes to Post Data Entry, No to Exit Excel", vbYesNo, "OPTION")
'if the answer is yes
If x = vbYes Then
With Sheets("TempTable") 'Table
'get the next avialable row in Sheet1
rw = .Range("A" & .Rows.Count).End(xlUp).Row + 1
'put the text box values in this row
.Range("A" & rw).Value = TextBox1.Value 'Ticket
.Range("B" & rw).Value = TextBox2.Value 'Line
.Range("C" & rw).Value = TextBox3.Value 'OldESN
.Range("K" & rw).Value = TextBox4.Value 'Date
.Range("D" & rw).Value = TextBox5.Value 'PONumber
.Range("E" & rw).Value = TextBox6.Value 'NewESN
.Range("F" & rw).Value = TextBox7.Value 'SKU
.Range("I" & rw).Value = TextBox8.Value 'Requestor
.Range("G" & rw).Value = CmbBoxDescript.Value
.Range("H" & rw).Value = TextBox9.Value 'Remarks
.Range("J" & rw).Value = CmbBoxDepartment.Value
End With
'clear the text boxes
TextBox2.Value = " "
TextBox3.Value = " "
TextBox6.Value = " "
End
End If
'if it equals no
If x = vbNo Then
MainForm.Hide
'close the userform
End If
End Sub
Bookmarks