error in search based on combo box

  • Thread starter twas via AccessMonster.com
  • Start date
T

twas via AccessMonster.com

I've got a very simple form with a single combo box called cmbPickUser with
code:

Private Sub cmdOpenUserForm_Click()
On Error GoTo Err_cmdOpenUserForm_Click

Dim stLinkCriteria As String
stLinkCriteria = BuildCriteria("[cmbPickUser]", dbText, cmbPickUser)
DoCmd.OpenForm "frmUsers", , , stLinkCriteria
If (Me.chkCloseOn.Value) Then
DoCmd.Close acForm, "frmFindUser"
End If

Exit_cmdOpenUserForm_Click:
Exit Sub

Err_cmdOpenUserForm_Click:
MsgBox Err.Description
Resume Exit_cmdOpenUserForm_Click

End Sub

but when I run it, rather than getting the selected value from the combo box,
I'm getting a message box asking for cmbPickUser as a parameter. I'm
obviously making some trival syntax error, but I can't find it. I've tried
specifying cmbPickUser.Value and cmbPickUser.SelText - and get parameter
queries for those referencens. Help!

thanks
twas
 
T

twas via AccessMonster.com

That code had a number of errors, stemming from the fact that cmbPickUser was
a combo box in the form used by the user to find a record, and a field that
did not appear in the frmUsers form. After setting the record source of both
forms to a query that had the same username (yep, the original version had
different record sources with different field names...dumb), and some
corrections to the code, it now works. The code is now:

Private Sub cmdOpenUserForm_Click()
On Error GoTo Err_cmdOpenUserForm_Click
Dim stSelectedUser As String
Dim stLinkCriteria As String
stSelectedUser = cmbPickUser
stLinkCriteria = "([LastFirst] = """ & stSelectedUser & """ )"
DoCmd.OpenForm "frmUsers", , , stLinkCriteria
If (Me.chkCloseOn.Value) Then
DoCmd.Close acForm, "frmFindUser"
End If

Exit_cmdOpenUserForm_Click:
Exit Sub

Err_cmdOpenUserForm_Click:
MsgBox Err.Description
Resume Exit_cmdOpenUserForm_Click

Now if I'd gotten enough sleep last night to see this without getting
frustrated...

twas

I've got a very simple form with a single combo box called cmbPickUser with
code:

Private Sub cmdOpenUserForm_Click()
On Error GoTo Err_cmdOpenUserForm_Click

Dim stLinkCriteria As String
stLinkCriteria = BuildCriteria("[cmbPickUser]", dbText, cmbPickUser)
DoCmd.OpenForm "frmUsers", , , stLinkCriteria
If (Me.chkCloseOn.Value) Then
DoCmd.Close acForm, "frmFindUser"
End If

Exit_cmdOpenUserForm_Click:
Exit Sub

Err_cmdOpenUserForm_Click:
MsgBox Err.Description
Resume Exit_cmdOpenUserForm_Click

End Sub

but when I run it, rather than getting the selected value from the combo box,
I'm getting a message box asking for cmbPickUser as a parameter. I'm
obviously making some trival syntax error, but I can't find it. I've tried
specifying cmbPickUser.Value and cmbPickUser.SelText - and get parameter
queries for those referencens. Help!

thanks
twas
 

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