Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2004
    Location
    Greenville, SC
    Posts
    271

    Unanswered: move from form to form using code??

    I have a form we use for our work order. I use a form that is continious. It work fine, except when I want to tab out of this form into the other form. Is there an easy way to do this?
    I am in my "FormWorkOrderData" and tab into the "Footage Form" where I enter:
    Amount
    Footage
    Floor type
    Actual Amount
    Actual Footage
    Actual Floor Type
    Basically I would like it if the Actual Floor Type is Null or "", for it to take me to the "FormWorkOrderData" to text Box "Forman Notes1"

    What event and where can I put it so this will work?
    I'm trying something like this:
    Private Sub ActualFloor_LostFocus()
    If Me!ActualFloor = "" Then

    End If
    End Sub
    I just can't think how to get back to the main form "FormWorkOrderData"

    Thank You,
    Michael
    Gotta to do some code

  2. #2
    Join Date
    Nov 2003
    Posts
    1,487
    Sure....Try this....
    Code:
    Private Sub ActualFloor_LostFocus()
       ' Skip past errors. You will want to put a handler of sorts in here.
       On Error Resume Next
       ' If the ActualFloor field is null (contains no data) then....
       If IsNull(Me.ActualFloor) Then 
    	  ' Set focus onto the "FormWorkOrderData" Form.
    	  DoCmd.SelectObject acForm, "FormWorkOrderData"
    	  ' Place focus onto a control (if you like) within the "FormWorkOrderData" Form.
    	  Forms![FormWorkOrderData].myControlNameonForm.SetFocus
    	  ' If you don't want to move focus to a control then delete the above line.
       End If
    	 ' whatever you wanted to put here if data
    	 ' was provided in ActualFloor field.
       End Sub
    End Sub
    You can put this code in either the LostFocus event or the BeforeUpdate event. More handling may be required if put into the BeforeUpdate event.

    You can use the same method in your other Forms as well.


  3. #3
    Join Date
    Mar 2004
    Location
    Greenville, SC
    Posts
    271
    Thank you CyberLynx,
    I am getting a Runtime error 2489 "The object "FormWorkOrderData" isn't open.
    ??
    Of course it is open it had the focus right before I went into the subform??
    I check to see if I had the form spelled correctly, thinking that might be the problem. It's right!

    Any ideas?

    Thank You
    Michael
    Gotta to do some code

  4. #4
    Join Date
    Mar 2004
    Location
    Greenville, SC
    Posts
    271
    Actually, I did mispell it!!!! I got it! Thank you.

    Now, Instead of sending the focus to a control, can I send the focus to page 4? When I send it to the control the page is off kilter. I have a Macro that does it in other parts of the form "Page4Macro"

    Thank You for any help!
    Michael
    Gotta to do some code

  5. #5
    Join Date
    Nov 2003
    Posts
    1,487
    Whatever you can do in Macro, you can also do with VBA code. Take a look at the structure of your Macro and simply apply it to VBA.


  6. #6
    Join Date
    Mar 2004
    Location
    Greenville, SC
    Posts
    271
    Tried to enter it as such:

    Forms![FrmWorkOrderData].PageBreak325.SetFocus

    I guess because it is not a control, it would not work. It gave me a Runtime error 438


    Michael
    Gotta to do some code

  7. #7
    Join Date
    Mar 2004
    Location
    Greenville, SC
    Posts
    271
    When I use a Macro "Page4Macro", it works fine. I just can't get it to work in VBA?


    Michael
    Gotta to do some code

  8. #8
    Join Date
    Nov 2004
    Location
    Bangor, ME USA
    Posts
    44
    Surfacesys,

    If using MSA2K or above you can have access convert the macro to code for you.

    highlight your macro, then right-click and choose save as...

    name your new module (function) and in the second box choose module from thedrop-down box.

    this will convert the macro to a function for you and just be sure that whereever you use the macro before you change it to read =newfunctionname()

    once it works then you can delete your now not used macro.

    the only macro I don't think you can convert is an autoexec one.

    HTH
    Kevin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •