Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Object Required Compile Error

Posted on 2007-12-06
6
Medium Priority
?
319 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
Technology Partners: 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 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

636 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