Having a reference problem with VBA

kilobyte

Registered User.
Local time
Today, 15:43
Joined
Oct 5, 2005
Messages
52
Well, thanks to SJ McAbney I have a nice chart on referencing subforms from the main form and what not. I'm still having trouble making it work, so I am sure there is something that I don't understand here.

Code:
Private Sub cmdNewCat_Click() 
Me.frmNavSNewCat.Visible = True
Me!frmNavSNewCat.Form!txtCatParID = Me.txtCurrent '<---This is the one the debugger highlights.
Me!FrmNamsNewCat.Form!txtCatName = ""
Me!FrmNamsNewCat.Form!txtCatNote = ""

End Sub

When I click the cmdNewCat Button, I get this error:


Run-time error '-2146500594 (800f000e)':

Method 'Form' of object '_SubForm failed


Anybody know what I'm doing wrong?
 
When setting focus to a control in a sub form you must first set the focus to the subform and then to the control...

Me!frmNavSNewCat.SetFocus
Me!frmNavSNewCat.Form!txtCatParID = Me.txtCurrent
 
Thanks a lot man I didn't know that. I'll give it a try tomorrow.
 
Ok, I added the SetFocus to the Code, and I am still getting the same error.

Is this the right way to do this?

The form is a navigator, allowing the user to move back and forth through categories and subcategories. It keeps track of the CatID of the current category.

When the user clicks the 'new category' button it should create a new recrod (category,) reveal the subform and automatically put the current category's ID number into the parentID field of the new category, effectively making it a new sub category. So is

Me!frmNavSNewCat.Form!txtCatParID = Me.txtCurrent

the right way to assign values like this?
 

Users who are viewing this thread

Back
Top Bottom