ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   User Defined Type not Defined (https://www.excelbanter.com/excel-programming/406356-re-user-defined-type-not-defined.html)

Carrie_Loos via OfficeKB.com

User Defined Type not Defined
 
Thanks Dave - once again. the Option Explicit work wonders. Apparently I was
way too tiered for this yesterday and should have just left it alone. Many
cudos to you for all your assistance with this project.

Carrie

Dave Peterson wrote:
Add this line to the top of your userform module:

Option Explicit

This will make you declare your variables. It would have caught the typo (one
vs ell) and the typo with TestBox vs TextBox.

Option Explicit
Private Sub CommandButton1_Click()
Dim LastRow As Range
Dim Response As Long

Set LastRow = Keys.Range("b65536").End(xlUp)

LastRow.Offset(1, 0).Value = TextBox1.Text

MsgBox "Record written to Training List"

Response = MsgBox("Do you want to enter another record?", vbYesNo)

If Response = vbYes Then
TextBox1.Text = ""
TextBox1.SetFocus
Else
Unload Me
End If
End Sub

Here is the code I got from the Microsoft site for "How to Use a UserForm for
Entering Data" But I cannot get the code to work. I get a compile error, User

[quoted text clipped - 26 lines]
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200802/1



--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200802/1


Dave Peterson

User Defined Type not Defined
 
It may seem like more work to have to declare your variables. But I bet you
spent more time searching for the problem than you would have spent declaring
the variables.

If you want to make "Option Explicit" show up in every new module, you can use:
Open the VBE
Tools|Options|Check Require Variable Declaration



"Carrie_Loos via OfficeKB.com" wrote:

Thanks Dave - once again. the Option Explicit work wonders. Apparently I was
way too tiered for this yesterday and should have just left it alone. Many
cudos to you for all your assistance with this project.

Carrie

Dave Peterson wrote:
Add this line to the top of your userform module:

Option Explicit

This will make you declare your variables. It would have caught the typo (one
vs ell) and the typo with TestBox vs TextBox.

Option Explicit
Private Sub CommandButton1_Click()
Dim LastRow As Range
Dim Response As Long

Set LastRow = Keys.Range("b65536").End(xlUp)

LastRow.Offset(1, 0).Value = TextBox1.Text

MsgBox "Record written to Training List"

Response = MsgBox("Do you want to enter another record?", vbYesNo)

If Response = vbYes Then
TextBox1.Text = ""
TextBox1.SetFocus
Else
Unload Me
End If
End Sub

Here is the code I got from the Microsoft site for "How to Use a UserForm for
Entering Data" But I cannot get the code to work. I get a compile error, User

[quoted text clipped - 26 lines]
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200802/1



--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200802/1


--

Dave Peterson


All times are GMT +1. The time now is 12:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com