View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Henry[_5_] Henry[_5_] is offline
external usenet poster
 
Posts: 104
Default Can I program a userform via spreadsheet?

Phillips,

You need to show the userform first and get that to pull the first data from
the worksheet.
You'll need a button on the form to get the next row of data into it (until
you reach the end)
The code behind the form would be something like:

Public MyRow as Integer
MyRow = 2 'To avoid headers

Private Sub Myform_Initialize()
TextBox1.Text = Sheets("Data").Range("A2").Value '1st Name
TextBox2.Text = Sheets("Data").Range("B2").Value '1st Address
End Sub

Private Sub NextBtn_Click()
MyRow = MyRow +1
If MyRow <= Sheets("Data").Last Used.Rows.Count Then 'Is it past the last
row?
TextBox1.Text = Sheets("Data").Range("A" & MyRow).Value 'Name
TextBox2.Text = Sheets("Data").Range("B" & MyRow).Value 'Address
Myform.Repaint
End If
End Sub


HTH
Henry


"Phillips" wrote in message
news:S1cxb.313809$HS4.2778403@attbi_s01...
Can I create a spreadsheet and then "build" a userform from it?

Example:

Speadsheet1 has 5 columns

A B C D

E
F G H
LabelName Type Title_name VarName TabOrder

CrossRefSheet
CrossRefCol Style
Name TexBox 1 Name_ 1
data A
Name label 1
Address TexBox 2 Add_ 2
data B


Spreadsheet2 is called Data
It is build like:
Name Address

Here is what I want the form to look like:
----------------------------------------------------------
| Name: | | Address: | |

|
|
|
|
|
----------------------------------------------------------

Here is what I think the code should flow like: but have no idea of the
syntax...

select spreadsheet1
recloop=0
do while recloop <= reccount
mLabelName = spreadsheet.A & recloop
mTYPE = spreadsheet.B & recloop
mMarker = spreadsheet.C & recloop
mStyle = spreadsheet.E & recloop
mTagOrder = spreadsheet.D & recloop
mWorkSheet = spreadsheet.F & recloop
mWorkCol = spreadsheet.G & recloop

if mType = "label"
.Caption = mLabelName
.Style = mStyle
create object. mLabelName

else if mType = "Textbox"

.Caption = mLabelName
.Style = mStyle
.Tag = mTagOrder
create object. mLabelName
mLabelName =end while
Textbox & mMarker = " worksheet " & mWorkSheet & mWorkCol
endif




end loop





TIA
Phil