Dear all,
I'm creating my first ever userform, and whilst I've created the form itself I need to tell it where to output.
I have named all the Textboxes, and I was planning to modify the following code to put the data into a worksheet:
---
Add code to the cmdAdd button
Select the cmdAdd button
On the Menu bar, choose View | Code.
This creates a procedure, where you can add your code.
Where the cursor is flashing, enter the following code:
Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("PartsData")
'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
'check for a part number
If Trim(Me.txtPart.Value) = "" Then
Me.txtPart.SetFocus
MsgBox "Please enter a part number"
Exit Sub
End If
'copy the data to the database
ws.Cells(iRow, 1).Value = Me.txtPart.Value
ws.Cells(iRow, 2).Value = Me.txtLoc.Value
ws.Cells(iRow, 3).Value = Me.txtDate.Value
ws.Cells(iRow, 4).Value = Me.txtQty.Value
'clear the data
Me.txtPart.Value = ""
Me.txtLoc.Value = ""
Me.txtDate.Value = ""
Me.txtQty.Value = ""
Me.txtPart.SetFocus
End Sub
(With thanks, I've lifted this from www.contextures.com/xlUserform01.html)
---
Now I've realised that if I do it this way when I come to the "'copy the data to the database" part I have 68 items to put in, and some of the box names are quite long! Is there either a way to output all the box names so I can cut and paste them into the code, or can I get them to output both the name in the label next to the text box AND the text box itself, one above the other so I know what is what?
Any help on this would be gratefully received. As I'm sure you can tell, my VBA knowledge is virtually zero!
Many thanks,
Chris
Bookmarks