?
Solved

Object Required Compile Error

Posted on 2007-12-06
6
Medium Priority
?
318 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
What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

 
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 200 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

764 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