form name not object name standard

B

bindurajeesh

with the following code:

sqlstr1 = "select filelocation,menulabellocation, menuid from menus where
menuname = '" & txtMenuName & "'"
Set rs2 = CurrentDb.OpenRecordset(sqlstr1)
txtMenuLocation = rs2!FileLocation
txtMenuLabel = rs2!MenuLabelLocation
'rs2.Close
subfrmMenuDates.Visible = True
'subfrmMenuDates.LinkChildFields = "menus!MenuID"
'subfrmMenuDates.LinkMasterFields = "menuwhenused!MenuID"
subfrmMenuDates.SourceObject = "SELECT MonthYear.Month, MonthYear.Year,
MenuWhenUsed.MenuID" & _
" FROM MenuWhenUsed INNER JOIN MonthYear ON MenuWhenUsed.MonthYearID =
MonthYear.DateID" & _
" Where MenuWhenUsed.MenuID = " & rs2!MenuID

rs2.Close

a blow up occurs at subfrmmenudates.sourceobject with this message:

the form name you entered doesn't follow Microsoft Access object naming rules.

Any wisdom would be great.
 
D

Douglas J. Steele

It looks as though you're trying to set the RecordSource for the subform.
Assuming that's correct, try:

subfrmMenuDates.Form.RecordSource = _
"SELECT MonthYear.Month, MonthYear.Year, " & _
"MenuWhenUsed.MenuID FROM MenuWhenUsed INNER JOIN MonthYear " & _
"ON MenuWhenUsed.MonthYearID = MonthYear.DateID" & _
" Where MenuWhenUsed.MenuID = " & rs2!MenuID

The SourceObject property is actually the name of the form being used as a
subform, and your SQL statement certainly doesn't following the naming rules
for a form! <g>
 
B

bindurajeesh

I now get this message.

you entered an expression that has an invalid reference to the property
recordsource.

Thank you for your input. I will look forward to further comment.
 
D

Douglas J. Steele

I was assuming that subfrmMenuDates was the name of the subform control on
your main form. If that's not the case, what is it?
 
Top