moving focus to subform

J

Jerry Crosby

I have a form/subform set up with 4 buttons whose on-click property sets the
source for the subform. For example, the on click code for one is:
Me.frmReservationInfo.SourceObject = "frmReservation-Past"
What I want to be able to do now is to move the focus to that subform so I
can analyze a particular field. If it meets certain criteria, it will show
the form as requested (i.e., the SourceObject will remain the same).
However, if the field doesn't meet the criteria, the SourceObject will be a
different form.

How do I do that?

(For the curious, the form is a reservation-type form. The main form
contains the general data about the person. Clicking the button will fill
the subform with the past reservation records for that person (arrival date,
departure date, rooms they rented, number of guests, etc). However, if they
have no past reservations, I'd like it to fill the subform with a different
form that says something like, "This person has no current or pending
reservations." The analysis is made on the arrival date field.)

Jerry
 
J

Jeff

Jerry said:
I have a form/subform set up with 4 buttons whose on-click property sets the
source for the subform. For example, the on click code for one is:
Me.frmReservationInfo.SourceObject = "frmReservation-Past"
What I want to be able to do now is to move the focus to that subform so I
can analyze a particular field. If it meets certain criteria, it will show
the form as requested (i.e., the SourceObject will remain the same).
However, if the field doesn't meet the criteria, the SourceObject will be a
different form.

How do I do that?

(For the curious, the form is a reservation-type form. The main form
contains the general data about the person. Clicking the button will fill
the subform with the past reservation records for that person (arrival date,
departure date, rooms they rented, number of guests, etc). However, if they
have no past reservations, I'd like it to fill the subform with a different
form that says something like, "This person has no current or pending
reservations." The analysis is made on the arrival date field.)

Jerry

Hi Jerry,

I have a similar code used in my

Private Sub Comando4_Click()
On Error GoTo Err_Comando4_Click


'Declare the variables.
Dim Result
Dim i As Integer


'Put code in a loop


Do Until i = "1"
i = "0"

' Use DLookUp to find info in table (the form is based on table info).

Result = DLookup("[Active]", "tbAlunosDetails", "[AlunoRef] = " &
Me.AlunoRef)
'Active = look up info in this field
'tbAlunosDetails = the table to look in
'[AlunoRef] = " & Me.AlunoRef) is the Where clause

' Use IF Condition to change subformControl Form

If Result = "Sim" Then 'Your criteria to show which form

Me.SubformControlName.SourceObject = "AlunoInfo"
'Change subformcontrolname to yours!

Else

Me.SubformControlName.SourceObject = "AlunoPag"

End If

'End the loop
i = i + 1
Loop

Exit_Comando4_Click:
Exit Sub

Err_Comando4_Click:
MsgBox Err.Description
Resume Exit_Comando4_Click

End Sub

Hope it helps!

Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top