making a cross reference form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm working on updating a database for work in access97, (will be completely rebuilding it in the near future, but in the mean time, I need to get the existing one to work better) and am building a form for locating records based on knowing only one out of a possible 9 fields. I have a form with 9 unbound controls, VBA code that builds an SQL statement for a QueryDef based on whatever criteria field(s) were populated, and a subform with controls for all fields I want to see in the returned record(s). I modified some of the code available in the QRYSMP97.mdb download in the knowledge base and the query returns what I want, but I now have 2 somewhat interrelated problems.

#1 - I don't want to see the query when I execute the code, all I want to see are the results posted in the subform. maybe I don't completely understand what querydef does. does a query have to be open in order for a form to use it? right now I have the query loading - so I know that's why it shows up - and I have left it that way so as to know that I got the proper response from that section of code. my docmd.openquery line will dissappear once i know what else to put in it's place to show the data in the subform instead of the query.

#2 - I don't know how to tell the subform to go look at the query that was made after each time I run the code. If I close the form and reopen it, the data I searched for prior to closing shows up, but that's the only way I've been able to get any response out of my subform. I don't know if I need a hidden control that serves as the parent/child refrence or what - I don't have any bound controls on my main form right now. I tried at one point, and was getting either no response, or an error about null values in primary keys. (defining indexes and primary keys has been a headache - there wern't any when I got my hands on the database to work on it) Anyone have any suggestions? My boss is looking to try and have this fixed ... yesterday :-)
 
On Fri, 23 Jul 2004 18:40:03 -0700, "Amanda Payton" <Amanda
#1 - I don't want to see the query when I execute the code, all I want to see are the results posted in the subform. maybe I don't completely understand what querydef does. does a query have to be open in order for a form to use it? right now I have the query loading - so I know that's why it shows up - and I have left it that way so as to know that I got the proper response from that section of code. my docmd.openquery line will dissappear once i know what else to put in it's place to show the data in the subform instead of the query.

No, the Query need not be opened. Just build the SQL string and assign
it to the subform's Recordsource:

Me.subMySubform.Form.Recordsource = strSQL
#2 - I don't know how to tell the subform to go look at the query that was made after each time I run the code. If I close the form and reopen it, the data I searched for prior to closing shows up, but that's the only way I've been able to get any response out of my subform. I don't know if I need a hidden control that serves as the parent/child refrence or what - I don't have any bound controls on my main form right now. I tried at one point, and was getting either no response, or an error about null values in primary keys. (defining indexes and primary keys has been a headache - there wern't any when I got my hands on the database to work on it) Anyone have any suggestions? My boss is looking to try and have this fixed ... yesterday :-)

The above should fix this.
 
Back
Top