Solved

Object Required Compile Error

Posted on 2007-12-06
6
312 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
  • 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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 - Access MVP) 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now