Solved

Object Required Compile Error

Posted on 2007-12-06
6
317 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
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!

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

717 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