Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2003
    Location
    Europe
    Posts
    369

    Question Unanswered: specifying open-criteria for form AND subform with cmdbutton?

    I would like to open a form that contain a subform by the click of a command button, WHILE specifying not only which record to open on the main form, but also wich of the related sub-records to display in the subform. How can this be done by the code on the OnClick event?

    D.

  2. #2
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    openargs again! personally i never use them.

    you have a perfectly serviceable form hosting the button you intend to click... code in that form can put whatever you like in however many forms and nested subforms you can imagine.

    your choice of using textboxes on the form in A's stored queries, or more elegantly, writing SQL and setting .recordsource (or .rowsource depending on your plans) in the other forms/subforms

    izy
    currently using SS 2008R2

  3. #3
    Join Date
    Aug 2003
    Location
    Argentina
    Posts
    465

    Re: specifying open-criteria for form AND subform with cmdbutton?

    Originally posted by kedaniel
    I would like to open a form that contain a subform by the click of a command button, WHILE specifying not only which record to open on the main form, but also wich of the related sub-records to display in the subform. How can this be done by the code on the OnClick event?

    D.
    En el ejemplo siguiente se utiliza la propiedad AbrirArgs (OpenArgs) para abrir el formulario Empleados en un registro de empleado específico y se muestra cómo establece el método OpenForm la propiedad AbrirArgs (OpenArgs). Este procedimiento se puede ejecutar como convenga, por ejemplo, cuando se produce el evento AfterUpdate de un cuadro de diálogo personalizado que se usa para introducir información nueva acerca de un empleado.

    Sub AbrirEnGómez()
    DoCmd.OpenForm "Empleados", acNormal, , , acReadOnly, , "Gómez"
    End Sub

    Sub Form_Open(Cancel As Integer)
    Dim cadNombreEmpleado As String
    ' Si la propiedad OpenArgs contiene el nombre del empleado,
    ' busca el registro de empleado correspondiente y lo muestra
    ' en el formulario. Por ejemplo, si OpenArgs contiene "Gómez",
    ' se mueve al primer registro "Gómez".
    cadNombreEmpleado = Forms!Empleados.OpenArgs
    If Len(cadNombreEmpleado) > 0 Then

    DoCmd.GoToControl "Apellido"
    DoCmd.FindRecord cadNombreEmpleado, , True, , True, , True
    End If
    End Sub

    En el ejemplo siguiente se utiliza el método FindFirst para buscar el registro del empleado especificado en la propiedad AbrirArgs (OpenArgs).

    Private Sub Form_Open(Cancel As Integer)
    If Not IsNull(Me.OpenArgs) Then
    Dim cadNombreEmpleado As String
    cadNombreEmpleado = Me.OpenArgs
    Dim RS As Recordset
    Set RS = Me.RecordsetClone
    RS.FindFirst "Apellido = '" & cadNombreEmpleado & "'"
    If Not RS.NoMatch Then
    Me.Bookmark = RS.Bookmark
    End If
    End If
    End Sub
    Saludos
    Norberto

Posting Permissions

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