Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 135
Default create automatic form when opening template

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
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default create automatic form when opening template

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
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 135
Default create automatic form when opening template

Thanks Dave. This looks like it should work. I'll try it out.
~ 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

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 135
Default create automatic form when opening template

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

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default create automatic form when opening template

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


  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 135
Default create automatic form when opening template

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

  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 135
Default create automatic form when opening template

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

  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default create automatic form when opening template

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
  #9   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 135
Default create automatic form when opening template

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

  #10   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default create automatic form when opening template

You can use the userform_initialize event to do what you want:

Option Explicit
Private Sub UserForm_Initialize()
Me.txthome.setFocus
End Sub

Me is the object that owns the code--in this case, it's your userform.


Horatio J. Bilge, Jr. wrote:

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


--

Dave Peterson


  #11   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 135
Default create automatic form when opening template

Dave,
Thank you for all of your help.
~ Horatio


"Dave Peterson" wrote:

You can use the userform_initialize event to do what you want:

Option Explicit
Private Sub UserForm_Initialize()
Me.txthome.setFocus
End Sub

Me is the object that owns the code--in this case, it's your userform.


Horatio J. Bilge, Jr. wrote:

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


--

Dave Peterson

  #12   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default create automatic form when opening template

Glad you're getting it working!

Horatio J. Bilge, Jr. wrote:

Dave,
Thank you for all of your help.
~ Horatio

"Dave Peterson" wrote:

You can use the userform_initialize event to do what you want:

Option Explicit
Private Sub UserForm_Initialize()
Me.txthome.setFocus
End Sub

Me is the object that owns the code--in this case, it's your userform.


Horatio J. Bilge, Jr. wrote:

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


--

Dave Peterson


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I stop the automatic opening of Template Help in Excel? TMC Excel Discussion (Misc queries) 6 May 11th 10 08:34 AM
how to generate a unique form # when using an excel form template PJE Excel Worksheet Functions 1 May 24th 06 11:00 PM
How do I create a form template that will be sequential numbered Gilly Excel Discussion (Misc queries) 1 September 13th 05 10:37 PM
Opening a template form & renaming it from a cell input automatica John Galt Excel Discussion (Misc queries) 0 April 19th 05 09:16 PM
create a data entry form template in Excel 2003? david.bottomley@haltoncollege Excel Discussion (Misc queries) 0 January 19th 05 09:59 AM


All times are GMT +1. The time now is 02:04 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"