You're doing the right thing to build the field names for the query so you will display the name in datasheet view. I.e. the "AS [fldname]" will name the columns. However, your code doesn't look like strQuery ends up with the correct Select statement syntax. It looks like strQuery is going to be:
Select fieldx, fieldy, fieldz, from tblHours;
Notice the extra comma and space after fieldz.
I don't know why your form is showing at all. Maybe the qdf.SQL = strQuery statement simply isn't accepting the new value??? The Form_Load event code works because it's using whatever SQL is in the querydef whether it is the correct statement or not.
Try putting:
Debug.Print Err.Description
Debug.Print strQuery
Debug.Print qdf.SQL
after qdf.SQL = strQuery. Of course the Err.Description will tell you if there is an error. Your test() function doesn't have error handling. But if the procedure that calls test() has error handling, you could be missing the error. Also, if the second and third lines don't print, error handling is taking over before your routine finishes. If the second and third lines are identical, the new value was accepted. At that point I don't know what's going on?
Also try:
debug.print Me.RecordSource
in Form_Load to be sure you have the expected record source.
Randall J Weers
Membership Vice President
Pacific NorthWest Access Developers Group
http://www.pnwadg.org