By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,921 Members | 1,466 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,921 IT Pros & Developers. It's quick & easy.

Problem setting a Form variable

P: 8
Hello. I am trying to set an object variable to a 'datasheet form' that I have so that I can manipulate the column widths programmically. I am doing it in exactly the same way that I am doing it for another 'datasheet form'. With one, it works perfectly, with the other, I cannot set the variable. I get an "Object Required" error. But there does not seem to be any differences in the forms, and the code is exactly the same. Here is the code (that causes the error):
Expand|Select|Wrap|Line Numbers
  1. Private Sub Child274_Enter()
  2. Dim frm As Form
  3. Set frm = Form_frmtblObsoleteParts
  4.  
  5. MsgBox frm.chrObsoletePN.ColumnWidth
  6. MsgBox frm.chrPartRevision.ColumnWidth
  7. MsgBox frm.chrMakeBuy.ColumnWidth
  8. MsgBox frm.chrQtyOnHand.ColumnWidth
  9. MsgBox frm.chrQtyOnOrder.ColumnWidth
  10. MsgBox frm.chrCostPart.ColumnWidth
  11. MsgBox frm.chrTotalPrice.ColumnWidth
  12.  
  13. End Sub
Feb 28 '14 #1

✓ answered by NeoPa

You've already found the first point I was going to make. The properies of the form include one called .HasModule (Near the bottom of the list). Set this to Yes if you want a module to be associated with it (Obviously your approach works too).

When referring to an open form it is more common (and more precise) to do so via the Forms() collection :
Expand|Select|Wrap|Line Numbers
  1. Forms("frmtblObsoleteParts")
or :
Expand|Select|Wrap|Line Numbers
  1. Forms!frmtblObsoleteParts
Form_frmtblObsoleteParts is, technically, a reference to the class rather than the instance.

Referring to Items on a Sub-Form gives further details.

Share this Question
Share on Google+
5 Replies


NeoPa
Expert Mod 15k+
P: 31,492
Where is the error message and what line does it occur on?
Mar 1 '14 #2

P: 8
It is:
Run-time error '424'
Object Required

Occurs on line 3 of the code when I try to set the variable. It is acting as if the form does not exist. But it does.

Thanks,
Mike
Mar 4 '14 #3

P: 8
It is working now. I looked at the VBA project, and there was no object for it there. So I created an open event and deleted it just so that there would be an object for the form in the VBA project. Now it is working fine.
Mar 4 '14 #4

NeoPa
Expert Mod 15k+
P: 31,492
You've already found the first point I was going to make. The properies of the form include one called .HasModule (Near the bottom of the list). Set this to Yes if you want a module to be associated with it (Obviously your approach works too).

When referring to an open form it is more common (and more precise) to do so via the Forms() collection :
Expand|Select|Wrap|Line Numbers
  1. Forms("frmtblObsoleteParts")
or :
Expand|Select|Wrap|Line Numbers
  1. Forms!frmtblObsoleteParts
Form_frmtblObsoleteParts is, technically, a reference to the class rather than the instance.

Referring to Items on a Sub-Form gives further details.
Mar 4 '14 #5

P: 8
Very useful... Thank you very much.
Mar 4 '14 #6

Post your reply

Sign in to post your reply or Sign up for a free account.