PDA

View Full Version : Solved: linking userforms



ashgull80
04-12-2012, 02:11 AM
hi
i have a text box with a list of numbers in it, i woud like to select a number from the list and the link it to another textbox in userform.
so if i select 01 in the combo box then i want new user form to have a text box that displays 01
thanks ash

Bob Phillips
04-12-2012, 02:42 AM
Launch the userform from the first, and just reference that property

Userform1.ComboBox1.Value

ashgull80
04-12-2012, 07:31 AM
i have 4 option buttons in userform1 and which ever one is selected with then open its relevent userform2/3/4/5
so do i set it to
if
option button 1 = true then. userform1.show?

Bob Phillips
04-12-2012, 07:56 AM
Yep.

ashgull80
04-12-2012, 08:08 AM
thank you one more question, i have a userform with an txt box with id numbers that realte to data in a sheet, i want the userform to input data i add to the correct row. so if the number is 1001 i need it to enter the details on the row that has 1001 in column 1

Bob Phillips
04-12-2012, 08:22 AM
Just find the row number


rownum = Application.Match(Me.TextBox1.Text, Worksheets("Sheet1").Columns("I"),0)

and use that row to populate other cells


With Worksheets("Sheet1")

.Cells(rownum, "A").Value = "some value"
.Cells(rownum, "B").Value = "another value"
'etc.
End With

ashgull80
04-12-2012, 08:39 AM
here is the code i have used
Private Sub cmdEnter_Click()
rownum = Application.Match(Me.txteditjobNumber.Text, Worksheets("JobList").Columns("B"), 0)
'copy the data to the database
With Worksheets("joblist")
.Cells(rownum, "C").Value = txteditcustomernumber
.Cells(rownum, "D").Value = txteditcustomername
'etc.
End With
'close The Form
Unload Me
End Sub
but comes up with a error 13 type mismatch

Bob Phillips
04-12-2012, 10:24 AM
Where is the error?

ashgull80
04-12-2012, 10:54 AM
Cells(rownum, "C").Value = txteditcustomernumber

Bob Phillips
04-12-2012, 01:32 PM
Do you know what the value of rownum is? Are the text box names correct?

ashgull80
04-12-2012, 01:49 PM
yeh the text box names are correct,
i have in column B the job numbers starting at 12001 and going to 12008 at the moment (job numbers will increase) and then in columns c,d,e ect are the details of that job, customer name, address number ect ect.

Bob Phillips
04-12-2012, 03:10 PM
Then I am at a loss. Can you post the workbook?

ashgull80
04-13-2012, 01:43 AM
what does the 0 represent at the end of this code?
rownum = Application.Match(Me.txteditjobNumber.Text, Worksheets("JobList").Columns("B"), 0)

Bob Phillips
04-13-2012, 01:46 AM
It just means look for an exact match.

ashgull80
04-13-2012, 01:55 AM
ok could it be to do with where the data is stored in worksheet?
as row 1 is empty, row 2 is a header and the data starts in row 3. column A is empty, column B is the job number columns C,D,E ect have the data in them corrosponding to the job jumber.

Aussiebear
04-13-2012, 01:57 AM
All this we could see if you would kindly post a sample workbook?

ashgull80
04-13-2012, 02:15 AM
i will post a sample workbbok shortly.
thank you

ashgull80
04-13-2012, 09:54 AM
here is a small sample sheet

ashgull80
04-14-2012, 05:26 AM
did the sample woorkbook help and make sense?

Tinbendr
04-17-2012, 10:32 AM
Excel is treating the Job# as numbers and in the Match you are passing the userform field which is a string.

Convert the field to a number.

rownum = Application.Match(CInt(Me.txteditjobNumber.Value), Worksheets("JobList").Columns("B"), 0)

You probably should have an error trap checking for this.

(Bob, even if I change the format of the column to text, the match still can't find it. Is this normal?)

ashgull80
04-18-2012, 02:01 PM
This still didn't work.

BrianMH
04-18-2012, 02:43 PM
I tried it and it worked for me. Are you still getting an error or is something else not working?

ashgull80
04-18-2012, 11:48 PM
Can you adjust the attachment then post back so I can see where I'm going wrong

BrianMH
04-19-2012, 12:12 AM
Here you are.

ashgull80
04-19-2012, 05:19 AM
i dont know what was wrong code was exactly the same but rewrote it and working fine now. thank you