Button to open subform within current form?

KevinSlater

Registered User.
Local time
Today, 22:37
Joined
Aug 5, 2005
Messages
249
hello, is it possible to add some code below to make this button open the subform "attendance" within the current form this code is on, rather than opening it in a new seperate window?


Private Sub Open_subform_attendance_Click()
On Error GoTo Err_Open_subform_attendance_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "SUBFORM: ATTENDANCE DETAILS"
stLinkCriteria = "[SHIFT_DATE]=" & "#" & Me![SHIFT_DATE] & "#"


DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Open_subform_attendance_Click:
Exit Sub

Err_Open_subform_attendance_Click:
MsgBox Err.Description
Resume Exit_Open_subform_attendance_Click

End Sub
 
not sure if it will work, but wjat about

subform.sourceObject = stDocName

then probably

subform.refresh
(or something similar)
 
Just open your form, add a subform/subreport control, this will probably be called child0 depending on what version of access you're using, then just place this code in your command button substituting FormName for whatever your form is called.

Child0.sourceobject = "FormName"
 
Ok, tried but dont think that will work workmad. James think ive got it working now, it will display records in the subform after the shiftdate & shiftname is entered on the form & when the button is pressed but if i enter just a shiftname i would like the subform to refresh with the data for that shift, but it doesnt at the moment (only if a shiftdate & shiftname are entered together) anyone have any ideas how i could fix this?

Private Sub Open_subform_attendance_Click()
On Error GoTo Err_Open_subform_attendance_Click

Dim stDocName As String
Dim stLinkCriteria As String


'added code below
Child31.SourceObject = "SUBFORM: ATTENDANCE DETAILS"

stLinkCriteria = "[SHIFTNAME]=" & "'" & Me![SHIFTNAME] & "'"
stLinkCriteria = "[SHIFT_DATE]=" & "#" & Me![SHIFT_DATE] & "#"



Exit_Open_subform_attendance_Click:
Exit Sub

Err_Open_subform_attendance_Click:
MsgBox Err.Description
Resume Exit_Open_subform_attendance_Click



End Sub

Private Sub SHIFT_DATE_AfterUpdate()

End Sub
 
Last edited:
Code:
Private Sub Open_subform_attendance_Click()
On Error GoTo Err_Open_subform_attendance_Click
Dim stDocName As String
Dim stLinkCriteria As String
Child31.SourceObject = "SUBFORM: ATTENDANCE DETAILS"
if both.value = yes then stLinkCriteria = "[SHIFTNAME]=" & "'" & Me![SHIFTNAME] & "' and[SHIFT_DATE]=" & "#" & Me![SHIFT_DATE] & "#" else stLinkCriteria = "[SHIFTNAME]=" & "'" & Me![SHIFTNAME] & "'""
me.filter = stlinkcriteria
me.filteron
Exit_Open_subform_attendance_Click:
Exit Sub
Err_Open_subform_attendance_Click:
MsgBox Err.Description
Resume Exit_Open_subform_attendance_Click
End Sub

Try that, you'll need to add a checkbox called both, also you may need to tweak it yourself as I'm at work so i'm not entirely sure if this will work.
 
Ok James, thanks a lot for that code, although I havent been able to get it working yet :-( but i will keep trying, access doesnt red out any of the code so i guess it could be not to far of but might need something else added to it. Also does the checkbox need to be created on the main form? (not the subform). I dont think it likes that line of the code (if both.value = yes......)
 
Ok im struggling to get this to work, anyone have any suggestions?, ive tried playing about with the code you gave me james but no luck yet.
 

Users who are viewing this thread

Back
Top Bottom