data from the spreadsheet into a form

N

nureen_lakhani1

Hey

Any help on this one would be really appreciated!

I need to get the data from a particular row within a spreadsheet -
into a form which I have designed using Visual Basic. I have created
the form.

The user would put in the reference number - which would refer to
column a in the spreadsheet and then all the relative data would come
up in the boxes with the form - the user would then be able to print
of the form???

If anyone could let me know what I need to do - or point to a tutorial
which can help me - please let me know.

Thank you
Nureen x
 
Z

Zone

Nureen, here's one way to do it. Show your form in the VBA editor. Add a
button to your form to fetch the data from the spreadsheet once the
reference number has been entered. Set the button's caption to "Get Data"
and attach this code to the button:
Private Sub CommandButton1_Click()
Dim j As Long
For j = 2 To Cells(65536, "a").End(xlUp).Row
If CStr(Cells(j, "a")) = Me.TextBox1 Then
Me.TextBox2 = Cells(j, "b")
Me.TextBox3 = Cells(j, "c")
Exit For
End If
Next j
End Sub
I have just assumed the data you want to show is in columns B and C. Of
course, you will need to add more lines as needed and change the names of
the text boxes and the cell references as appropriate.

To print the form, add a button and set its caption to Print. Attach this
code to that button:
Private Sub CommandButton2_Click()
Me.PrintForm
End Sub

HTH, James
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top