Solved

Object Required Compile Error

Posted on 2007-12-06
6
316 Views
Last Modified: 2013-11-28
I know I'm doing something stupid, but HELP!  (I'm a newbie).  I have 2 unlinked forms.   I am trying to copy the contents of Form 1, Field1 to Form 2, Field2 using an event, but I'm getting an "Object Required - Compile Error".

Please help.
Private Sub CertificateID_GotFocus()
On Error GoTo Err_AddNew_Click
 
Dim strField1 As String
    
Set strField1 = Forms![Form1)]![Field1]
    
Forms![Form2)]![Field2] = strField1
 
Exit_CertificateID_GotFocus:
    Exit Sub
    
Err_AddNew_Click:
    MsgBox Err.Clear
    Resume Exit_CertificateID_GotFocus
 
End Sub

Open in new window

0
Comment
Question by:cnbehler
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 75
ID: 20423281
try this

Private Sub CertificateID_GotFocus()
On Error GoTo Err_AddNew_Click
 
Dim strField1 As String
   
strField1 = Forms![Form1]![Field1]   '** removed right paren and Set
   
Forms![Form2]![Field2] = strField1    '** removed right paren
 
Exit_CertificateID_GotFocus:
    Exit Sub
   
Err_AddNew_Click:
    MsgBox Err.Clear
    Resume Exit_CertificateID_GotFocus
 
End Sub
0
 
LVL 75
ID: 20423295
You have parens here:

[Form1)]
[Form2)]

is that a typo ?

What line is causing the error ?

mx
0
 

Author Comment

by:cnbehler
ID: 20423668
Yes, the parens are typos and are not in my code.   The error was on the line strField1 = Forms![Form1]![Field1] but removing the set fixed it!

I forgot to add that field2 is bound.

I have a new error now:  "Microsoft Access can't find the form FORM1 referred to in a macro express or VB code."

Thanks for your help!
Private Sub CertificateID_GotFocus()
On Error GoTo Err_AddNew_Click
 
Dim strField1 As String
    
strField1 = Forms![Form1]![Field1]
    
Forms![Form2]![Field2] = strField1
 
Exit_CertificateID_GotFocus:
    Exit Sub
    
Err_AddNew_Click:
    MsgBox Err.Description
    Resume Exit_CertificateID_GotFocus
 
End Sub

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75
ID: 20423705
Is Form1 *open* when you execute this code ?

Any possibility of a spelling error.

That error message is usually pretty self-explanatory ...

mx
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 50 total points
ID: 20423722
btw ... typically, you only use 'Set' for object variables ... for examle:

Dim oCtl as Control
Set oCtl = Me.Text1

Dim rst as dao.Recordset
Set rst = CurrentDb.OpenRecordset("MyRecordset", dbopendynaset)

there are many more examples ...

mx

0
 

Author Closing Comment

by:cnbehler
ID: 31413259
Thanks for your help - I'm rethinking using 2 forms.  I may post another question later.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question