ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,226
- Office Version
- 2007
- Platform
- Windows
Evening,
Code in use is shown below.
I wish to run the code when the Enter button is pressed & ONLY if the userform called DatabaseUserForm is open to cover hitting Enter by mistake when your not using the userform etc.
Currently the code below worked fine & did what it was supposed to do when on a command button, "new row & value entered in cell A6"
I then added the text in Red which now when i press the Enter button i need to press it twice, then the userform closes but no new row was added & no value was entered into cell A6
Code in use is shown below.
I wish to run the code when the Enter button is pressed & ONLY if the userform called DatabaseUserForm is open to cover hitting Enter by mistake when your not using the userform etc.
Currently the code below worked fine & did what it was supposed to do when on a command button, "new row & value entered in cell A6"
I then added the text in Red which now when i press the Enter button i need to press it twice, then the userform closes but no new row was added & no value was entered into cell A6
VBA Code:
Private Sub Workbook_Open()
Application.OnKey "{ENTER}"
Rows("6:6").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A6:Q6").Borders.LineStyle = xlContinuous
Range("A6:Q6").Borders.Weight = xlThin
Range("A6:Q6").Interior.ColorIndex = 6
Range("$Q$6").Value = "'NO NOTES FOR THIS CUSTOMER"
Range("$Q$6").HorizontalAlignment = xlCenter
Sheets("DATABASE").Range("B6").Select
Cancel = 0
If TextBox1.Text = "" Then
Cancel = 1
MsgBox "YOU MUST ENTER A CUSTOMERS NAME", vbCritical, "DATABASE USER FORM NAME TRANSFER"
TextBox1.SetFocus
End If
If Cancel = 1 Then
Exit Sub
End If
Dim i As Long
Dim x As Long
Dim ctrl As Control
Dim LastRow As Long
With ThisWorkbook.Worksheets("DATABASE")
.Range("A6").Value = TextBox1.Text
End With
Unload DatabaseUserForm
End Sub
Last edited by a moderator: