From a form open another form to a particular record

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Cutepaloma1
    New Member
    • Dec 2009
    • 3

    From a form open another form to a particular record

    I'm a NEWBIE!!!

    I have two forms frmStudent and frmCourse. frmStudent has a field [MR#], from the frmStudent I would like to open frmCourse, select the desire course but as soon as I select the course, I want frmCourse to make sure it is using the same[MR#]. I noticed that if you make frmCourse a subform to frmStudent it automatically does it but I would like to make this action happen with a command button and not as a subform. Help!!! How would I do that? Thank you!!!!
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    kindly post the code that you are working on.

    Comment

    • Cutepaloma1
      New Member
      • Dec 2009
      • 3

      #3
      Code:
      Private Sub Form_Current()
      If Me.NewRecord Then
      [EmployeeID].Defaulty=Forms![Student]![EmployeeID]
      End If
      End Sub
      Last edited by debasisdas; Dec 12 '09, 01:00 PM. Reason: Formatted using code tags.

      Comment

      • patjones
        Recognized Expert Contributor
        • Jun 2007
        • 931

        #4
        Hi Cutepaloma -

        I'm much more experienced with VBA, but I think the general concept I'm going to lay out should still be applicable. Suppose you have a button cmdGetCourse and text box txtEmployeeID on frmStudent. You can put all your code for opening frmCourse in the Click event for cmdGetCourse:

        Code:
        Private Sub cmdGetCourse_Click()
        
        If IsNull(Me.txtEmployeeID) Then
             MsgBox "No employee ID present! Please try again..."
             Exit Sub
        Else
             DoCmd.OpenForm "frmCourse",acNormal,,,,,Me.txtEmployeeID
        EndIf
        
        End Sub

        This is a very basic subroutine of course, but notice the last argument in the OpenForm command. Whatever you put in here will get passed to frmCourse as a parameter. In the module for frmCourse, you can access it using Me.OpenArgs (look at the help pages for more information about OpenArgs) - and use it for whatever purpose you need within the code for frmCourse. Like I mentioned before, the syntax in VB.NET may be a bit different, but the logic will still be the same I think.

        Another option for you to consider is setting up a global variable that holds the employee ID. Since it's global you would be able to access the variable from any module in your project, including frmCourse.

        Hope this helps.

        Comment

        • Cutepaloma1
          New Member
          • Dec 2009
          • 3

          #5
          OMG!!! It worked!!! Thank you. Thank you.

          Comment

          • patjones
            Recognized Expert Contributor
            • Jun 2007
            • 931

            #6
            You're welcome. I'm happy to hear it. Just make sure you test the other branch of the IF statement...you should have some mechanism in place to trap the situation in case an ID is not present for some reason. You can also look at the help pages for MsgBox, because it takes many arguments besides the message string to make the box look more user friendly.

            Comment

            Working...