Juan Cornetto
New Member
- Joined
- Mar 5, 2013
- Messages
- 44
I have a workbook which auto closes after a period of inactivity.
Updating of the worksheets is achieved by the use of a user form which is designed to transfer the data to the next empty row
On occasion (not every time) the userform data is transferred to a random row, replacing the data already there, instead of the next empty row. Usually this is the top row of the table under the title row.
It appears but I cannot confirm it, that this happens after the workbook has closed automatically somewhere.
The code for the auto close and the data transfer is shown below.
I would appreciate any thoughts on the problem.
AUTO CLOSE
Sub TimedMsgbox()
Dim WSH As Object
Set WSH = CreateObject("WScript.Shell")
Select Case WSH.Popup(TM_TEXT, TM_DURATION, TM_TITLE, vbOKCancel + vbExclamation + vbDefaultButton2)
Case vbOK
Call ShutDown
Case vbCancel
Call StopTimer
Call SetTimer
Case -1
Call ShutDown
End Select
End Sub
Sub ShutDown()
Application.DisplayAlerts = False
Application.Quit
End Sub
DATA TRANSFER
Private Sub SubmitCommandButton_Click()
Dim Emptyrow As Long
'Dim erow As Integer
Dim ws As Worksheet
Set ws = Worksheets("Register")
Emptyrow = Sheets("Register").Cells(Rows.Count, 5).End(xlUp).Offset(Abs(Cells(Rows.Count, 5).End(xlUp).Value <> ""), 0).Row
ws.Cells(Emptyrow, 2).Value = DateTextBox.Value
ws.Cells(Emptyrow, 2) = Format(DateTextBox, "dd mmm yyyy")
ws.Cells(Emptyrow, 59).Value = TimeTextBox.Value
ws.Cells(Emptyrow, 60).Value = TextBox1.Value
ws.Cells(Emptyrow, 4).Value = "Behaviour"
ws.Cells(Emptyrow, 5).Value = DescriptionTextBox.Value
ws.Cells(Emptyrow, 6).Value = DoTextBox.Value
ws.Cells(Emptyrow, 7).Value = ReportTextBox.Value
ws.Cells(Emptyrow, 8).Value = TextBox3.Value
ws.Cells(Emptyrow, 9).Value = ActionTextBox.Value
ws.Cells(Emptyrow, 10).Value = ActioneeComboBox.Value
ws.Cells(Emptyrow, 11).Value = TargetTextBox.Value
ws.Cells(Emptyrow, 11) = Format(TargetTextBox, "dd mmm yyyy")
If CheckBox19.Value = True Then ws.Cells(Emptyrow, 34).Value = "X"
If CheckBox20.Value = True Then ws.Cells(Emptyrow, 35).Value = "X"
If CheckBox21.Value = True Then ws.Cells(Emptyrow, 36).Value = "X"
If CheckBox22.Value = True Then ws.Cells(Emptyrow, 37).Value = "X"
If CheckBox23.Value = True Then ws.Cells(Emptyrow, 38).Value = "X"
If CheckBox24.Value = True Then ws.Cells(Emptyrow, 39).Value = "X"
If CheckBox25.Value = True Then ws.Cells(Emptyrow, 40).Value = "X"
If CheckBox26.Value = True Then ws.Cells(Emptyrow, 41).Value = "X"
If CheckBox27.Value = True Then ws.Cells(Emptyrow, 42).Value = "X"
If CheckBox28.Value = True Then ws.Cells(Emptyrow, 43).Value = "X"
If CheckBox29.Value = True Then ws.Cells(Emptyrow, 44).Value = "X"
If CheckBox30.Value = True Then ws.Cells(Emptyrow, 45).Value = "X"
If CheckBox31.Value = True Then ws.Cells(Emptyrow, 46).Value = "X"
If CheckBox32.Value = True Then ws.Cells(Emptyrow, 47).Value = "X"
If CheckBox33.Value = True Then ws.Cells(Emptyrow, 48).Value = "X"
If CheckBox34.Value = True Then ws.Cells(Emptyrow, 49).Value = "X"
If CheckBox35.Value = True Then ws.Cells(Emptyrow, 50).Value = "X"
If CheckBox36.Value = True Then ws.Cells(Emptyrow, 51).Value = "X"
If PositiveOptionButton.Value = True Then
ws.Cells(Emptyrow, 15).Value = "POS"
ElseIf NegativeOptionButton.Value = True Then
ws.Cells(Emptyrow, 15).Value = "NEG"
Else
ws.Cells(Emptyrow, 15).Value = ""
End If
Unload Me
End Sub
Updating of the worksheets is achieved by the use of a user form which is designed to transfer the data to the next empty row
On occasion (not every time) the userform data is transferred to a random row, replacing the data already there, instead of the next empty row. Usually this is the top row of the table under the title row.
It appears but I cannot confirm it, that this happens after the workbook has closed automatically somewhere.
The code for the auto close and the data transfer is shown below.
I would appreciate any thoughts on the problem.
AUTO CLOSE
Sub TimedMsgbox()
Dim WSH As Object
Set WSH = CreateObject("WScript.Shell")
Select Case WSH.Popup(TM_TEXT, TM_DURATION, TM_TITLE, vbOKCancel + vbExclamation + vbDefaultButton2)
Case vbOK
Call ShutDown
Case vbCancel
Call StopTimer
Call SetTimer
Case -1
Call ShutDown
End Select
End Sub
Sub ShutDown()
Application.DisplayAlerts = False
Application.Quit
End Sub
DATA TRANSFER
Private Sub SubmitCommandButton_Click()
Dim Emptyrow As Long
'Dim erow As Integer
Dim ws As Worksheet
Set ws = Worksheets("Register")
Emptyrow = Sheets("Register").Cells(Rows.Count, 5).End(xlUp).Offset(Abs(Cells(Rows.Count, 5).End(xlUp).Value <> ""), 0).Row
ws.Cells(Emptyrow, 2).Value = DateTextBox.Value
ws.Cells(Emptyrow, 2) = Format(DateTextBox, "dd mmm yyyy")
ws.Cells(Emptyrow, 59).Value = TimeTextBox.Value
ws.Cells(Emptyrow, 60).Value = TextBox1.Value
ws.Cells(Emptyrow, 4).Value = "Behaviour"
ws.Cells(Emptyrow, 5).Value = DescriptionTextBox.Value
ws.Cells(Emptyrow, 6).Value = DoTextBox.Value
ws.Cells(Emptyrow, 7).Value = ReportTextBox.Value
ws.Cells(Emptyrow, 8).Value = TextBox3.Value
ws.Cells(Emptyrow, 9).Value = ActionTextBox.Value
ws.Cells(Emptyrow, 10).Value = ActioneeComboBox.Value
ws.Cells(Emptyrow, 11).Value = TargetTextBox.Value
ws.Cells(Emptyrow, 11) = Format(TargetTextBox, "dd mmm yyyy")
If CheckBox19.Value = True Then ws.Cells(Emptyrow, 34).Value = "X"
If CheckBox20.Value = True Then ws.Cells(Emptyrow, 35).Value = "X"
If CheckBox21.Value = True Then ws.Cells(Emptyrow, 36).Value = "X"
If CheckBox22.Value = True Then ws.Cells(Emptyrow, 37).Value = "X"
If CheckBox23.Value = True Then ws.Cells(Emptyrow, 38).Value = "X"
If CheckBox24.Value = True Then ws.Cells(Emptyrow, 39).Value = "X"
If CheckBox25.Value = True Then ws.Cells(Emptyrow, 40).Value = "X"
If CheckBox26.Value = True Then ws.Cells(Emptyrow, 41).Value = "X"
If CheckBox27.Value = True Then ws.Cells(Emptyrow, 42).Value = "X"
If CheckBox28.Value = True Then ws.Cells(Emptyrow, 43).Value = "X"
If CheckBox29.Value = True Then ws.Cells(Emptyrow, 44).Value = "X"
If CheckBox30.Value = True Then ws.Cells(Emptyrow, 45).Value = "X"
If CheckBox31.Value = True Then ws.Cells(Emptyrow, 46).Value = "X"
If CheckBox32.Value = True Then ws.Cells(Emptyrow, 47).Value = "X"
If CheckBox33.Value = True Then ws.Cells(Emptyrow, 48).Value = "X"
If CheckBox34.Value = True Then ws.Cells(Emptyrow, 49).Value = "X"
If CheckBox35.Value = True Then ws.Cells(Emptyrow, 50).Value = "X"
If CheckBox36.Value = True Then ws.Cells(Emptyrow, 51).Value = "X"
If PositiveOptionButton.Value = True Then
ws.Cells(Emptyrow, 15).Value = "POS"
ElseIf NegativeOptionButton.Value = True Then
ws.Cells(Emptyrow, 15).Value = "NEG"
Else
ws.Cells(Emptyrow, 15).Value = ""
End If
Unload Me
End Sub