access subforms

DJFuji

Diamond Member
Oct 18, 1999
3,643
1
76
I can't seem to find any MS access message boards on the web so I hope someone can help me out with this. It seems that I can't put any sort of vba code on a subform. If i create a form, then add a subform, then add a cmdbutton to the subform and use even the auto-generated code to run notepad, i get the same error no matter what i do. I've found that the process doesn't even reach the code--it stops and gives me the error before Ive even gotten to the first line. This is the error msg i get:

The expression onclick you entered as the event property setting produced the following error: A problem occurred while microsoft access was communicating with the OLE server or activeX control
*the expression may not result in the name of a macro, the name of a user-defined function, or [event procedure].
*There may have been an error evaluating the function, event, or macro.

I suppose I could solve this problem by placing the cmdbutton on the parent form, but then I don't know the vba code to access the fields within the subform. (I want to change a apply a filter to the subform via optiongroups). Any ideas here??
 

theknight571

Platinum Member
Mar 23, 2001
2,896
2
81
Ok...this took me a minute....but its one of the more interesting problems I've worked on in a couple of weeks. (Work's kinda boring at the moment)

Disclaimer: Your milage may vary depending upon your forms and the way they are set up.

I was able to do what you are trying to do by inserting code into the Frame's "on-click" event that changes the subforms RecordSource.

Example:



<<
Private Sub Frame8_Click()
Select Case Frame8.Value
Case 1 'Problem
Me!SubForm.Form.RecordSource = &quot;Select * from Tickets where Category = 'Problem'&quot;
Case 2 'Misc
Me!SubForm.Form.RecordSource = &quot;Select * from Tickets where Category like 'Misc'&quot;
Case 3 'Install
Me!SubForm.Form.RecordSource = &quot;Select * from Tickets where Category like 'Install'&quot;
End Select
End Sub
>>



Since the Frame can only be numeric values I used the Select Case to translate the numbers into their correct terms.

The command is

<< Me![Name of your subform].Form.RecordSource=... >>




I hope this helps, or at least puts you in the right direction.

- TK

P.S. Another good source for Access information is The Access Web. Although they do not have a fourm.