Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Microsoft Access can't find the form referred to in the code

Status
Not open for further replies.

kuanli

Technical User
Jan 28, 2002
22
CA
I have the following VB code:

Sub trial2()

Dim appAccess As Access.Application
Dim strDB As String
Dim strFormName As String

' Initialize string to database path.
strDB = "c:\AA_xx\Workplan.mdb"
' Initialize string to Form name.
strFormName = "frmWorkPlan"

Set appAccess = _
CreateObject("Access.Application")

' Open database in Microsoft Access.
appAccess.OpenCurrentDatabase strDB

' Open form
appAccess.DoCmd.OpenForm strFormName

' Modify form
Forms(strFormName).Controls("status").RowSource = "inProgress"

appAccess.DoCmd.Save acForm, strFormName

appAccess.CloseCurrentDatabase
Set appAccess = Nothing

End Sub

But when I run it, I got problem with this line:
Forms(strFormName).Controls("status").RowSource = "inProgress"

And the message is that "Microsoft Access can't fine the form 'frmWorkPlan' referred to in a macro expression or Visual Basic code".

Since I have "openForm" on the previous line, I don't understand why it doesn't work.

Thanks.

Kuan


 
I believe your code should look like this:

appAccess.Forms(strFormName).Controls("status").RowSource = "inProgress"
 
Thank you so much! I've spent days on this and I was just about to give up. Thank you!

However, I've got a new problem this time. The code ran through with no problem, but when I opened the form to check, my change to rowSource was not there! Did I not change it? Or did I not save the change correctly?
 
Not sure. But, instead of this:
appAccess.DoCmd.Save acForm, strFormName

try this:
appAccess.DoCmd.Close acForm, strFormName, acSaveYes
 
You didn't do anything wrong. Run time changes in Access do NOT persist after the form closes. If you open the form in design mode then your changes should take effect. Try something like the following:

DoCmd.OpenForm "FormName",acDesign,,,acFormEdit,acHidden

Good Luck!
 
FancyPrairie and SBendBuckeye,

Thank you both very much!

Opening the form in design mode worked!
 
Good eye SBendBuckeye. I missed that it wasn't being opened in design view.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top