Change to combo box stops code from returning records

S

Scott B

Greetings,

The following code worked fine when the form had a text box, but when I
changed it to a combo box, it now does not return any records. What did I
miss?
-------
Private Sub cmdChooseGuest_Click()
On Error GoTo Err_cmdChooseGuest_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmGuestRecord"

stLinkCriteria = "[FirstName]=" & "'" & Me![FirstName] & "'"
stLinkCriteria = "[LastName]=" & "'" & Me![LastName] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdChooseGuest_Click:
Exit Sub

Err_cmdChooseGuest_Click:
MsgBox Err.Description
Resume Exit_cmdChooseGuest_Click

End Sub
 
D

Duane Hookom

I expect your combo box is bound to a primary key field that is not the
first or last name. Do you realize that the first stLinkCriteria line does
nothing?

Check the Row Source of your combo boxes to determine what field value is
actually returned by the combo.
 
S

Scott B

Duane,

Can the linked field be calculated or must it be a field in a table. Right
now I am trying to use a query field that concantates the name fields from
the table so I know which Smith I am viewing.

Thanks,
Scott B

Duane Hookom said:
I expect your combo box is bound to a primary key field that is not the
first or last name. Do you realize that the first stLinkCriteria line does
nothing?

Check the Row Source of your combo boxes to determine what field value is
actually returned by the combo.

--
Duane Hookom
MS Access MVP


Scott B said:
Greetings,

The following code worked fine when the form had a text box, but when I
changed it to a combo box, it now does not return any records. What did
I miss?
-------
Private Sub cmdChooseGuest_Click()
On Error GoTo Err_cmdChooseGuest_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmGuestRecord"

stLinkCriteria = "[FirstName]=" & "'" & Me![FirstName] & "'"
stLinkCriteria = "[LastName]=" & "'" & Me![LastName] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdChooseGuest_Click:
Exit Sub

Err_cmdChooseGuest_Click:
MsgBox Err.Description
Resume Exit_cmdChooseGuest_Click

End Sub
 
D

Duane Hookom

Why don't you just provide some information about your combo box such as
name, control source, row source (SQL), column count, bound column, column
widths,...

--
Duane Hookom
MS Access MVP


Scott B said:
Duane,

Can the linked field be calculated or must it be a field in a table.
Right now I am trying to use a query field that concantates the name
fields from the table so I know which Smith I am viewing.

Thanks,
Scott B

Duane Hookom said:
I expect your combo box is bound to a primary key field that is not the
first or last name. Do you realize that the first stLinkCriteria line does
nothing?

Check the Row Source of your combo boxes to determine what field value is
actually returned by the combo.

--
Duane Hookom
MS Access MVP


Scott B said:
Greetings,

The following code worked fine when the form had a text box, but when I
changed it to a combo box, it now does not return any records. What did
I miss?
-------
Private Sub cmdChooseGuest_Click()
On Error GoTo Err_cmdChooseGuest_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmGuestRecord"

stLinkCriteria = "[FirstName]=" & "'" & Me![FirstName] & "'"
stLinkCriteria = "[LastName]=" & "'" & Me![LastName] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdChooseGuest_Click:
Exit Sub

Err_cmdChooseGuest_Click:
MsgBox Err.Description
Resume Exit_cmdChooseGuest_Click

End Sub
 
S

Scott B

Here is the info on the combo box:
Name: cboGuestName
Row Source Type: Table/Query
Row Source: SELECT [qryMainGuests].[NAME1] FROM qryMainGuests;
Bound Column: 1
Column Count: 1

Here is the info on the Command Button:
Name: cmdChooseGuest
Enabled: yes
Code (On Click):
Private Sub cmdChooseGuest_Click()
On Error GoTo Err_cmdChooseGuest_Click
Dim stDocName As String
Dim stDocName2 As String
Dim stLinkCriteria As String
stDocName = "frmGuestRecord"
stDocName2 = "frmChooseGuest"
stLinkCriteria = "[NAME1]=" & "'" & Me![NAME1] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm = stDocName2, , , acSaveNo
Exit_cmdChooseGuest_Click:
Exit Sub
Err_cmdChooseGuest_Click:
MsgBox Err.Description
Resume Exit_cmdChooseGuest_Click
End Sub

Scott B

Duane Hookom said:
Why don't you just provide some information about your combo box such as
name, control source, row source (SQL), column count, bound column, column
widths,...

--
Duane Hookom
MS Access MVP


Scott B said:
Duane,

Can the linked field be calculated or must it be a field in a table.
Right now I am trying to use a query field that concantates the name
fields from the table so I know which Smith I am viewing.

Thanks,
Scott B

Duane Hookom said:
I expect your combo box is bound to a primary key field that is not the
first or last name. Do you realize that the first stLinkCriteria line
does nothing?

Check the Row Source of your combo boxes to determine what field value
is actually returned by the combo.

--
Duane Hookom
MS Access MVP


Greetings,

The following code worked fine when the form had a text box, but when I
changed it to a combo box, it now does not return any records. What
did I miss?
-------
Private Sub cmdChooseGuest_Click()
On Error GoTo Err_cmdChooseGuest_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmGuestRecord"

stLinkCriteria = "[FirstName]=" & "'" & Me![FirstName] & "'"
stLinkCriteria = "[LastName]=" & "'" & Me![LastName] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdChooseGuest_Click:
Exit Sub

Err_cmdChooseGuest_Click:
MsgBox Err.Description
Resume Exit_cmdChooseGuest_Click

End Sub
 
D

Duane Hookom

I don't see anywhere in your code that references cboGuestName.
Normally you would compare the value from a combo box to the primary key of
the record source of the form you are opening. NAME1 does not sound like a
primary key field.

--
Duane Hookom
MS Access MVP


Scott B said:
Here is the info on the combo box:
Name: cboGuestName
Row Source Type: Table/Query
Row Source: SELECT [qryMainGuests].[NAME1] FROM qryMainGuests;
Bound Column: 1
Column Count: 1

Here is the info on the Command Button:
Name: cmdChooseGuest
Enabled: yes
Code (On Click):
Private Sub cmdChooseGuest_Click()
On Error GoTo Err_cmdChooseGuest_Click
Dim stDocName As String
Dim stDocName2 As String
Dim stLinkCriteria As String
stDocName = "frmGuestRecord"
stDocName2 = "frmChooseGuest"
stLinkCriteria = "[NAME1]=" & "'" & Me![NAME1] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm = stDocName2, , , acSaveNo
Exit_cmdChooseGuest_Click:
Exit Sub
Err_cmdChooseGuest_Click:
MsgBox Err.Description
Resume Exit_cmdChooseGuest_Click
End Sub

Scott B

Duane Hookom said:
Why don't you just provide some information about your combo box such as
name, control source, row source (SQL), column count, bound column,
column widths,...

--
Duane Hookom
MS Access MVP


Scott B said:
Duane,

Can the linked field be calculated or must it be a field in a table.
Right now I am trying to use a query field that concantates the name
fields from the table so I know which Smith I am viewing.

Thanks,
Scott B

I expect your combo box is bound to a primary key field that is not the
first or last name. Do you realize that the first stLinkCriteria line
does nothing?

Check the Row Source of your combo boxes to determine what field value
is actually returned by the combo.

--
Duane Hookom
MS Access MVP


Greetings,

The following code worked fine when the form had a text box, but when
I changed it to a combo box, it now does not return any records. What
did I miss?
-------
Private Sub cmdChooseGuest_Click()
On Error GoTo Err_cmdChooseGuest_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmGuestRecord"

stLinkCriteria = "[FirstName]=" & "'" & Me![FirstName] & "'"
stLinkCriteria = "[LastName]=" & "'" & Me![LastName] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdChooseGuest_Click:
Exit Sub

Err_cmdChooseGuest_Click:
MsgBox Err.Description
Resume Exit_cmdChooseGuest_Click

End Sub
 

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