Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 3rd, 2006, 02:55 PM
Authorized User
 
Join Date: Jul 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem opening Form from search

I keep getting a run time error 2501 when I try to open a form to display the results of my search.

Here is my code..
I have been racking my brain any tips would be greatly appriciated!!

Code:
Option Compare Database   'Use database order for string comparisons

Private Sub cmdSearch_Click()
'Set the Dimensions of the Module
Dim strSQL As String, strOrder As String, strWhere As String
Dim dbNm As Database
Dim qryDef As QueryDef
Set dbNm = CurrentDb()

'Constant Select statement for the RowSource
strSQL = "SELECT tblDemographics.DG_ControlID " & _
"FROM tblDemographics"

strWhere = "WHERE"

strOrder = "ORDER BY tblDemographics.DG_ControlID;"


'Set the WHERE clause for the Listbox RowSource if information has been entered into a field on the form
If Not IsNull(Me.txtControlID) Then
strWhere = strWhere & " (tblDemographics.DG_ControlID) Like '*" & Me.txtControlID & "*'  AND"
End If

'Remove the last AND from the SQL statment
strWhere = Mid(strWhere, 1, Len(strWhere) - 5)

'Pass the SQL to the RowSource of the listbox

Me.lstCustInfo.RowSource = strSQL & " " & strWhere & "" & strOrder

End Sub


Private Sub lstCustInfo_DblClick(Cancel As Integer)
'Open frmCustomer based on the ID from lstCustInfo listbox


DoCmd.OpenForm "frmDemographics", , , "[DG_ControlID] = " & Me.lstCustInfo, , acDialog


End Sub
 
Old July 3rd, 2006, 03:07 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Hey Sprocket,

Nothing strikes me right off, but....

Try put a break point on the following line

Me.lstCustInfo.RowSource = strSQL & " " & strWhere & "" & strOrder

and when it hits that, put the following in the immediate window...

?strSQL & " " & " strWhere & "" & strOrder

My suspicion is that it might a problem with spaces or something similar.

HTH

Mike

Mike
EchoVue.com
 
Old July 3rd, 2006, 03:07 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

And welcome to the forum!

Mike
EchoVue.com
 
Old July 3rd, 2006, 03:25 PM
Authorized User
 
Join Date: Jul 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by echovue
 And welcome to the forum!

Mike
EchoVue.com
Thanks for the welcome!

I get the results in my list box just fine but when I double click one of the results to pull up the form for that item, that is when I get the error. The form I am pulling up has field in it from 3 other tables as well could that be what is hosing this up?

 
Old July 3rd, 2006, 03:33 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

From what I have found '2501' is a run-time error on the form being called. Try and open the form in design view, put the filter in on the properties and see if you can narrow it down that way. Without physically seeing the form being called, makes troubleshooting it a little tricky.

Mike

Mike
EchoVue.com
 
Old July 7th, 2006, 01:17 PM
Authorized User
 
Join Date: Jul 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey echo just a quick update I figured it out the other day. I am updating someone elses work so it can be difficult sometimes :). They were not using the controlID field to identify the records in that form... It was another field which is why I was not getting anything.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening 1 form from another jainin_shah9 C# 2005 5 February 18th, 2008 07:31 AM
problem with search-form Hylsan PHP Databases 0 May 4th, 2007 08:36 AM
Opening a Form arholly Access 1 January 17th, 2007 11:59 AM
Closing a form after opening another form rosebushr Access 2 January 7th, 2006 04:34 AM
Problem with Search Form DRuiz VB Databases Basics 3 June 6th, 2003 11:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.