简体   繁体   中英

MS Access setting RecordSource results in error

I like to use an unbound subform to display the result of an crosstab query. However following code

Me.subFormForecastSummary.Form.RecordSource = "SELECT ....."

results in this error message: "The expression you entered refers to an object that is closed or doesn't exist".

When I use the Source Object in the form designer and specify the select statement, then the code above works fine and I am able to set the property RecordSource.

The issue I am facing is that the select statement is based on a crosstab query and can contain a different number of columns (in my case weeks) depending on the master record. The issue I am facing is that the datasheet only displays the columns as per the original query specified in SourceObject (the data itself is refreshed though). Does anyone know how I can force the columns to be refreshed as well or how I can get overcome the error message?

Thanks

Thanks for the responses thus far. Based on the comments and further research I have decided on following solution:

  • Created a dummy query returning 1 record with the maximum number of columns. I have named them 001 trough to 100
  • Still created a subform and bound it to the dummy query
  • In VBA I then change the recordsource at runtime as required
  • Also in VBA rename the captions as required

You would think there should be a more elegant solution, but this works for me

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM