Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code does not work when switching from one form to next

Status
Not open for further replies.

kgerlitz

Technical User
Oct 2, 2004
84
0
0
US
I have a command button that when clicked is supposed to take me to a new form, start a new record, then change the size of a field and set the focus on this field.

Problem is, the form opens but then I get an error saying "Object Required" and the debug points to the "DateCreatedBy.Left = 4.125 * 1440" string of the code. I have a command button within this form that changes the field size using the same code and it works fine.

Does it still think I am on the first form and that is why I get the "Object Required" error. If so, how do I switch the focus to the new form so that it can find the object?

Thanks in advance.

Private Sub APNEW_Click()
Dim stDocName As String
stDocName = "AdoptiveParent"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Maximize
DoCmd.GoToRecord , , acNewRec
DateCreatedBy.Left = 4.125 * 1440
DateCreatedBy.Top = 0.3333 * 1440
DateCreatedBy.Width = 0.75 * 1440
DateCreatedBy.Height = 0.2083 * 1440
End Sub
 
Forms!AdoptiveParent!DateCreatedBy.Left = 4.125 * 1440

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
How are ya kgerlitz . . .
Code:
[blue]    Dim stDocName As String, ctl As Control
    
    stDocName = "AdoptiveParent"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    DoCmd.Maximize
    DoCmd.GoToRecord , , acNewRec
    
    Set ctl = Forms(stDocName)!DateCreatedBy
    
    ctl.Left = 4.125 * 1440
    ctl.Top = 0.3333 * 1440
    ctl.Width = 0.75 * 1440
    ctl.Height = 0.2083 * 1440
    
    Set ctl = Nothing[/blue]

Calvin.gif
See Ya! . . . . . .
 
Sorry to get back so late--tried them both and they work great. Thanks for both your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top