D
DrNoose
Hi!
I've got another project that I don't totally understand. The book I've
been using is pretty good (Access VBA for Absolute Beginners), but this
chapter is a little disjointed.
Here is the problem:
Declare a user-defined type called HomeData with elements
StreetAddress, City, State, SquareFottage, LotSize, and SalePrice in a
standard module. Create a form with six text boxes to add values to each
variable type element. In the general declarations area of the form,
create a single variable of HomeType to store the user-entered value.
Add two command buttons to the form, one called cmdAddHome and the other
cmdDisplayHomeData. In cmdAddHome Click event, store the data entered by
the user into your user-defined type variable. In cmdDisplayHomeData
Click event, display each element's value in a message box.
I've got the form designed with the text boxes and command buttons. I
think I understand what they want done, but not sure how to do the
module. When I try to enter data into the form, I get an error.
I'm supplying the data that I have in the module. If someone can tell me
what I'm doing wrong. The error tells me I have an "invalid inside
procedure"
I think I should be able to use HomeData in my cmdAddHome and it will
add the data that the user supplies and the HomeType I should be able to
use in cmdDisplayHomeData and it will spit the info back out in message
boxes. I'm just not sure about how to put the code into the module
correctly.
Thanks!
*************************************************************************************
Module Code:
Option Compare Database
Option Explicit
Public Sub HomeData()
Dim MyStreetAddress As String
Dim MyCity As String
Dim MyState As String
Dim MySquareFootage As String
Dim MyLotSize As String
Dim MySalesPrice As Currency
Type HomeData
HomeDataStreetAddress As String
HomeDataCity As String
HomeDataState As String
HomeDataSquareFootage As String
HomeDataLotSize As String
HomeDataSalesPrice As Currency
StreetAddress As String
City As String
State As String
SquareFootage As String
LotSize As String
SalesPrice As Currency
End Type
txtStreetAddress.Value = My.StreetAddress
txtCity.Value = My.City
txtState.Value = My.State
txtSquareFootage.Value = My.SquareFootage
txtLotSize.Value = My.LotSize
txtSalesPrice.Value = My.SalesPrice
MyStreetAddress = txtStreetAddress.Value
MyeCity = txtCity.Value
MyState = txtState.Value
MySquareFootage = txtSquareFootage.Value
MyLotSize = txtLotSize.Value
MySalesPrice = txtSalesPrice.Value
End Sub
Public Sub HomeType()
Type HomeType
MyStreetAddress As String
MyCity As String
MyState As String
MySquareFootage As String
MyLotSize As String
MySalesPrice As Currency
End Type
txtStreetAddress.Value = My.StreetAddress
txtCity.Value = My.City
txtState.Value = My.State
txtSquareFootage.Value = My.SquareFootage
txtLotSize.Value = My.LotSize
txtSalesPrice.Value = My.SalesPrice
MyStreetAddress = txtStreetAddress.Value
MyeCity = txtCity.Value
MyState = txtState.Value
MySquareFootage = txtSquareFootage.Value
MyLotSize = txtLotSize.Value
MySalesPrice = txtSalesPrice.Value
MsgBox "Your street address is: " & MyStreetAddress.Value
MsgBox "Your city is: " & MyCity.Value
MsgBox "Your state is: " & MyState.Value
MsgBox "Your square footage is: " & MySquareFootage.Value
MsgBox "Your lot size is: " & MyLotSize.Value
MsgBox "Your sales price is: " & MySalesPrice.Value
End Sub
I've got another project that I don't totally understand. The book I've
been using is pretty good (Access VBA for Absolute Beginners), but this
chapter is a little disjointed.
Here is the problem:
Declare a user-defined type called HomeData with elements
StreetAddress, City, State, SquareFottage, LotSize, and SalePrice in a
standard module. Create a form with six text boxes to add values to each
variable type element. In the general declarations area of the form,
create a single variable of HomeType to store the user-entered value.
Add two command buttons to the form, one called cmdAddHome and the other
cmdDisplayHomeData. In cmdAddHome Click event, store the data entered by
the user into your user-defined type variable. In cmdDisplayHomeData
Click event, display each element's value in a message box.
I've got the form designed with the text boxes and command buttons. I
think I understand what they want done, but not sure how to do the
module. When I try to enter data into the form, I get an error.
I'm supplying the data that I have in the module. If someone can tell me
what I'm doing wrong. The error tells me I have an "invalid inside
procedure"
I think I should be able to use HomeData in my cmdAddHome and it will
add the data that the user supplies and the HomeType I should be able to
use in cmdDisplayHomeData and it will spit the info back out in message
boxes. I'm just not sure about how to put the code into the module
correctly.
Thanks!
*************************************************************************************
Module Code:
Option Compare Database
Option Explicit
Public Sub HomeData()
Dim MyStreetAddress As String
Dim MyCity As String
Dim MyState As String
Dim MySquareFootage As String
Dim MyLotSize As String
Dim MySalesPrice As Currency
Type HomeData
HomeDataStreetAddress As String
HomeDataCity As String
HomeDataState As String
HomeDataSquareFootage As String
HomeDataLotSize As String
HomeDataSalesPrice As Currency
StreetAddress As String
City As String
State As String
SquareFootage As String
LotSize As String
SalesPrice As Currency
End Type
txtStreetAddress.Value = My.StreetAddress
txtCity.Value = My.City
txtState.Value = My.State
txtSquareFootage.Value = My.SquareFootage
txtLotSize.Value = My.LotSize
txtSalesPrice.Value = My.SalesPrice
MyStreetAddress = txtStreetAddress.Value
MyeCity = txtCity.Value
MyState = txtState.Value
MySquareFootage = txtSquareFootage.Value
MyLotSize = txtLotSize.Value
MySalesPrice = txtSalesPrice.Value
End Sub
Public Sub HomeType()
Type HomeType
MyStreetAddress As String
MyCity As String
MyState As String
MySquareFootage As String
MyLotSize As String
MySalesPrice As Currency
End Type
txtStreetAddress.Value = My.StreetAddress
txtCity.Value = My.City
txtState.Value = My.State
txtSquareFootage.Value = My.SquareFootage
txtLotSize.Value = My.LotSize
txtSalesPrice.Value = My.SalesPrice
MyStreetAddress = txtStreetAddress.Value
MyeCity = txtCity.Value
MyState = txtState.Value
MySquareFootage = txtSquareFootage.Value
MyLotSize = txtLotSize.Value
MySalesPrice = txtSalesPrice.Value
MsgBox "Your street address is: " & MyStreetAddress.Value
MsgBox "Your city is: " & MyCity.Value
MsgBox "Your state is: " & MyState.Value
MsgBox "Your square footage is: " & MySquareFootage.Value
MsgBox "Your lot size is: " & MyLotSize.Value
MsgBox "Your sales price is: " & MySalesPrice.Value
End Sub