Subject: Access can't find the form error
Posted By: bmurrin Post Date: 12/31/2003 1:55:09 PM
I am using a list box to select the record to display when opening another form in Access 2002(XP). When I run this code from a command button, I get an error message that says:

Run-time error '2450':
Microsoft Access can't find the form 'frmTest' referred to in a macro expression or Visual Basic code.

The form that won't open is in the same database and can be opened by this code:

DoCmd.OpenForm "frmTest"

Here is my code:

Dim rst As Recordset
Set rst = Forms!frmTest.RecordsetClone  'here is where the code stops
rst.Find "CustomerNumber = " & List0
Forms!frmTest.Bookmark = rst.Bookmark
DoCmd.Close acForm, "frmGoToRecordDialog"

Thanks for your help,

Bill Murrin
Nashville, TN

Nashville_Bill
Reply By: Steven Reply Date: 12/31/2003 11:30:21 PM
Not sure if this will fix yr problem or not - but try getting rid of the bang (!), as it's really just a remnant of the past - try using either
Forms.frmTest
or
Form_frmTest
HTH
Steven


I am a loud man with a very large hat. This means I am in charge
Reply By: bmurrin Reply Date: 1/1/2004 3:31:13 PM
Thanks for the reply Steven. I tried you suggestion, but I am still having problems and think maybe I should just make it a VB application. It will be a lot more work, but VB seems to be more stable for me.

Nashville_Bill
Reply By: jemacc Reply Date: 1/1/2004 9:35:34 PM
It looks like that form must first be open, then run your code.

Reply By: BethMoffitt Reply Date: 1/2/2004 9:12:23 AM
Once the form is opened, you can set the recordsource as follows:

Set rst = Me.RecordsetClone

But to open a form with a recordset based on the criteria selected in a list box or text box, your code would look something like the following:

Dim strCriteria as string

strCriteria = "[CustomerNumber]=" & Me![List0]
DoCmd.OpenForm "frmTest", , , strCriteria

HTH,

Beth Moffitt
Reply By: bmurrin Reply Date: 1/3/2004 1:27:03 PM
Beth,

Thanks a lot for the help. I followed an example in a VB6 manual and it wouldn't work. I guess it shouldn't have worked. It seems really simple when you get the code right, huh?

Bill Murrin

Nashville_Bill

Go to topic 8178

Return to index page 976
Return to index page 975
Return to index page 974
Return to index page 973
Return to index page 972
Return to index page 971
Return to index page 970
Return to index page 969
Return to index page 968
Return to index page 967