Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub Submit()
- Dim sh As Worksheet
- Dim tbl As ListObject
- Dim newRow As ListRow
- On Error GoTo ErrorHandler ' Set up error handling
- ' Check if the worksheet exists
- On Error Resume Next
- Set sh = ThisWorkbook.Sheets("05618")
- On Error GoTo ErrorHandler
- If sh Is Nothing Then
- MsgBox "Worksheet '05618' not found!", vbCritical
- Exit Sub
- End If
- ' Check if the table exists on the worksheet
- On Error Resume Next
- Set tbl = sh.ListObjects("TableOhFiveSixOneEight") ' Ensure this matches your table name
- On Error GoTo ErrorHandler
- If tbl Is Nothing Then
- MsgBox "Table 'TableOhFiveSixOneEight' not found on the worksheet '05618'!", vbCritical
- Exit Sub
- End If
- ' Try to add a new row to the table
- On Error Resume Next
- Set newRow = tbl.ListRows.Add(AlwaysInsert:=True)
- If Err.Number <> 0 Then
- MsgBox "Failed to add a new row: " & Err.Description, vbCritical
- Exit Sub
- End If
- On Error GoTo ErrorHandler
- ' Populate the new row with form data
- With newRow.Range
- .Cells(2, 1).Value = frmForm.txtMRN.Text
- .Cells(2, 2).Value = frmForm.txtName.Text
- .Cells(2, 3).Value = frmForm.txtID.Text
- .Cells(2, 4).Value = frmForm.cmbPhysician.Value
- .Cells(2, 5).Value = frmForm.cmbNurse.Value
- .Cells(2, 6).Value = frmForm.cmbStatus.Value
- .Cells(2, 7).Value = frmForm.cmbCycle.Value
- .Cells(2, 8).Value = frmForm.txtDate.Text
- .Cells(2, 9).Value = frmForm.cmbCalendar.Value
- .Cells(2, 10).Value = frmForm.cmbLabs.Value
- .Cells(2, 11).Value = frmForm.cmbRecist.Value
- .Cells(2, 12).Value = Application.UserName
- .Cells(2, 13).Value = Format(Now(), "MM/DD/YYYY")
- End With
- Exit Sub
- ErrorHandler:
- MsgBox "An error occurred: " & Err.Description, vbCritical
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement