Thanks. I like having the date format included.
One more questions - how can I change which object is in focus when the form
opens? Currently, the CommandButton is in focus, and I would like the focus
to be on the first text box ("txtHome"). I tried adding a line to the
workbook code, but it didn't work like I hoped:
Option Explicit
Private Sub Workbook_Open()
frmMeetInfo.Show
frmMeetInfo.txtHome.SetFocus
End Sub
"Dave Peterson" wrote:
Sorry, I didn't notice the question in your followup post.
You could also use:
ws.Range("a1").Value = Me.txtHome.Value
ws.Range("a2").Value = Me.txtVisiting.Value
ws.Range("a3").Value = Me.txtPool.Value
ws.Range("A4").Value = Me.txtDate.Value
You may want to apply the format you like to the date cell, too:
with ws.Range("A4") 'or ws.cells(4,1)
.numberformat = "mm/dd/yyyy"
.Value = Me.txtDate.Value
end with
Horatio J. Bilge, Jr. wrote:
I got it figured out. I changed the section of code that copies data to the
worksheet:
'copy the data to the workbook
ws.Cells(1,1).Value = Me.txtHome.Value
ws.Cells(1,2).Value = Me.txtVisiting.Value
ws.Cells(1,3).Value = Me.txtPool.Value
ws.Cells(1,4).Value = Me.txtDate.Value
"Horatio J. Bilge, Jr." wrote:
I changed the code to Workbook_Open() and it now opens correctly when I open
the workbook.
It appears to work well up to the point where it should copy the data into
cells in the workbook. I want the values from the four textboxes to go into
cells A1:A4 on the worksheet "Meet." Here is the code I adapted from Debra
Dalgleish's site:
Private Sub CmdUpdate_Click()
Dim ws As Worksheet
Set ws = Worksheets("Meet")
'check for Home Team
If Trim(Me.txtHome.Value) = "" Then
Me.txtHome.SetFocus
MsgBox "Please enter the Home Team"
Exit Sub
End If
'check for Visiting Team
If Trim(Me.txtVisiting.Value) = "" Then
Me.txtVisiting.SetFocus
MsgBox "Please enter the Visiting Team"
Exit Sub
End If
'check for Pool Location
If Trim(Me.txtPool.Value) = "" Then
Me.txtPool.SetFocus
MsgBox "Please enter the Pool Location"
Exit Sub
End If
'check for Date
If Trim(Me.txtDate.Value) = "" Then
Me.txtDate.SetFocus
MsgBox "Please enter the Date (m/dd/yyyy)"
Exit Sub
End If
'copy the data to the workbook
ws.Cells(A1).Value = Me.txtHome.Value
ws.Cells(A2).Value = Me.txtVisiting.Value
ws.Cells(A3).Value = Me.txtPool.Value
ws.Cells(A4).Value = Me.txtDate.Value
'close the MeetInfo form
Unload Me
End Sub
"Dave Peterson" wrote:
You have a couple of choices.
One move your macro to a General module--not behind ThisWorkbook and not behind
a worksheet. And keep that same name (Auto_Open).
Or keep the code in the same location and rename the procedu
Option Explicit
Private Sub Workbook_Open()
MeetInfo.show
End Sub
Horatio J. Bilge, Jr. wrote:
I've made a form, but so far, I can't get it to load when I open the
workbook, so I haven't been able to test if it works correctly. The form is
named MeetInfo. I put the following code under ThisWorkbook.
Option Explicit
Sub Auto_Open()
MeetInfo.Show
End Sub
Did I put it in the wrong place, or is there another step that I need to do?
Thanks,
~ Horatio
"Dave Peterson" wrote:
You can build your own userform:
Check Debra Dalgleish's site:
http://contextures.com/xlUserForm01.html
and these articles by Peter Aiken:
http://msdn2.microsoft.com/en-us/lib...ffice.10).aspx
http://msdn2.microsoft.com/en-us/lib...ffice.10).aspx
Then you could create a macro in a General module that shows your form each time
the workbook is opened:
Option Explict
Sub Auto_Open()
UserForm1.show
End Sub
Horatio J. Bilge, Jr. wrote:
I have created a workbook to score high school swim meets. In the header, I
have placed team names, date, etc.
I would like to write some code so that when I open the template, a form
pops up, and by completing the form, the header information will be filled in
automatically.
For example: Home team? Visiting eam? Date? Pool location?
Can someone help me with this, or suggest another way to accomplish the same
thing?
Thanks,
~ Horatio
--
Dave Peterson
--
Dave Peterson
--
Dave Peterson