I am using an unbound combo box to select a contact, then a button which opens a form for adding a record. The button has this code in the onclick event:
Private Sub Command438_Click()
If Len(Me.cbosrch & vbNullString) = 0 Then
Else
DoCmd.OpenForm "frmNewTeam", , , "[ConId] = " & Me!cbosrch.Column(0)
cbosrch = Null
End If
End Sub
Now I want to also have the contacts name set as the value of a textbox on the form. How do I append the code to do this?
Thanks
Open form and set value question
-
- Administrator
- Posts: 78790
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Open form and set value question
Where do we get the name from? Is it the second column of cbosrch?
Best wishes,
Hans
Hans
-
- 2StarLounger
- Posts: 198
- Joined: 21 Aug 2011, 02:32
Re: Open form and set value question
Yes, ConId is column(0), so the next column should be the name. I get a little confused with the numbering of columns in combo boxes.
-
- Administrator
- Posts: 78790
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Open form and set value question
You could use code like this:
where txtName is the name of the text box on frmNewTeam that you want to populate,
Code: Select all
Private Sub Command438_Click()
If Len(Me.cbosrch & vbNullString) > 0 Then
DoCmd.OpenForm "frmNewTeam", , , "[ConId] = " & Me.cbosrch.Column(0)
Forms!frmNewTeam!txtName = Me.cbosrch.Column(1)
Me.cbosrch = Null
End If
End Sub
Best wishes,
Hans
Hans
-
- 2StarLounger
- Posts: 198
- Joined: 21 Aug 2011, 02:32
Re: Open form and set value question
Perfect, thank you much :)