Results 1 to 13 of 13
  1. #1
    Derrick T. Davidson is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    142

    Close one form open another and set focus to a specific field

    Hi I am learning code with the help of you experts so apologies if this is very basic to you, here is my latest issue

    I close [form1], I open [form2] and want go to [fieldwidgets]



    I coded the following:
    *************************
    DoCmd.Close,""
    DoCmd.OpenForm"Form2",acNormal,"","",,acNormal
    DoCmnd.GoToRecordacForm,"form2", acLast
    Me.SetFocus "fieldwidgets"

    *************************
    I get the error
    Run-timeerror ‘424’:
    I know I am doing the set focus wrong, but not sure what is wrong??

    Objectrequired

  2. #2
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Where is the code at? Which form? Are the two forms linked?
    Also, you can't close the active form and then open another form. The DoCmd.OpenForm code goes before the close command.

  3. #3
    Derrick T. Davidson is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    142
    This code:
    ***************
    DoCmd.Close , "" DoCmd.OpenForm"form1", acNormal, "", "", ,acNormal
    DoCmd.GoToRecord acForm,"form2", acLast
    Me.SetFocus ”FieldWidgets”
    ******************
    works fine without the set focus line, it closes the active form opens the new one and goes to the last record?


  4. #4
    Derrick T. Davidson is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    142
    This code:
    ***************
    DoCmd.Close , ""
    DoCmd.OpenForm"form1", acNormal, "", "", ,acNormal

    DoCmd.GoToRecord acForm,"form2", acLast
    Me.SetFocus ”FieldWidgets”
    ******************
    works fine without the set focus line, it closes the active form opens the new one and goes to the last record?

  5. #5
    Derrick T. Davidson is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    142
    This code:
    ***************
    DoCmd.Close , ""
    DoCmd.OpenForm"form2", acNormal, "", "", ,acNormal

    DoCmd.GoToRecord acForm,"form2", acLast
    Me.SetFocus ”FieldWidgets”
    ******************
    works fine without the set focus line, it closes the active form opens the new one and goes to the last record?

  6. #6
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Try this. Is that your only issue?
    Me.FieldWidgets.SetFocus

  7. #7
    Derrick T. Davidson is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    142
    I get this

    Error Message
    **************
    Compile Error;
    Method or data member not found
    ********

  8. #8
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Then you need to refer to the name of the control, not the control source. Assuming you have typed it in correctly in the first place.

  9. #9
    Derrick T. Davidson is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    142
    Please letme explain what I am doing:
    1. The first input is a transaction this is a bulknumber used in financial records later i.e. 200
    2. After that a pop up (popup1) form breaks downthe transaction in to components
    a. i.e.
    b. Ink 50
    c. Paper 50
    d. Cartridge 100
    3. If this is a new supplier then the forms forcesthe user to enter the category of the supplier and closes popup1. Another pop up (popup2) shows to enterthe category
    i.e.
    a. Print Supplier
    b. Canvas supplier etc.
    4. After the category is entered the popup2closes and popup1 re-opens to continue entering the break down information,with the current settings popup1 goes to the initial (firstfield). What I am trying to do is go to the next entry point in popup2which is halfway down the form.

  10. #10
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Try this. Unsure what is going on?
    Forms!YourFormNameHere.SetFocus
    Me.yourfieldname.SetFocus

  11. #11
    Derrick T. Davidson is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    142
    Same error message, guess I will leave it alone.................

  12. #12
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Up to you. I still say check your field names and refer to the name and not the control.

    Good Luck!

    Going to bed now.

  13. #13
    Derrick T. Davidson is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    142
    Just in case anyone else is looking for an answer the solution is shown below

    Please letme explain what I am doing:

    1. The first input is a transaction this is a bulk number used in financial records later i.e. 200
    2. After that a pop up (popup1) form breaks down the transaction in to components
    i.e.
    a. Ink 50
    b. Paper 50
    c. Cartridge 100
    3. If this is a new supplier then the form popup1forces the user to enter the category of the supplier and closes the popup1window. Another pop up (popup2)opens to enter the category
    i.e.
    a. Print Supplier
    b. Canvas supplier
    c. Trucking, etc.
    4. After the category is entered a buttonis clicked the popup2 closes and popup1 re-opens to continue entering the break down information, with the current settings I had popup1went to the initial (first field). What I wanted to do is go to the next entry point in popup2 which is halfway down the form.
    5. After searching for the answer the code below is what I added to the button on click,and it works like a dream.

    *************************************************
    DoCmd.Close, ""
    DoCmd.OpenForm"popup1", acNormal, "", "", , acNormal
    DoCmd.GoToRecordacForm, "popup1", acLast
    Forms!popup1.SetFocus
    Forms!popup1.FieldWidgets.SetFocus
    ***********************************************

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 11-01-2013, 09:57 AM
  2. Replies: 1
    Last Post: 08-20-2013, 02:17 PM
  3. Open an external folder specific by a form field
    By AccessNoob16 in forum Forms
    Replies: 11
    Last Post: 04-09-2012, 01:30 PM
  4. Replies: 11
    Last Post: 01-26-2012, 01:22 PM
  5. Replies: 7
    Last Post: 11-29-2009, 01:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums