View Full Version : SQL, Form Question.


gbanks
09-17-2001, 11:30 AM
I would like to have the results of the SQL statement below populate a field in a form. The form is called testform and the field is called problem1. This SQL below gets he data I want I just don't know how to have it populate the field on the form. Thanks for the help.
Dim SQL$ As String
SQL$ = "SELECT [Problem] FROM [EIRReview_Frm];"

Alexandre
09-17-2001, 11:36 AM
Put
SELECT [Problem] FROM [EIRReview_Frm]
in the recordsource of your control problem1.

Alex

gbanks
09-17-2001, 04:03 PM
Thanks that does work but what if the form and the field already have a record and control source?

Pat Hartman
09-17-2001, 04:18 PM
You cannot use SQL statements as the controlSource for a control.

I sense some concept problem with what you are trying to do. If you want to populate a single field on a form, it is unlikely that you really want to use a query that does not include a where clause. You could not make use of a recordset that returned multiple rows. I would suggest replacing the SQL statement with a DLookUp() but that would also require a criteria statement which you have not supplied. Try posting a requirements statement and I'm sure someone will provide an appropriate method.

Alexandre
09-17-2001, 06:42 PM
Pat

I believe that this is a problem of terminology. My English is not always as accurate as it ought to be. Should I have said "Row source" instead of "recordsource"?

Please, do not tell me that I cannot do that.
Because I did it many times yet.
Yes I did.
Snif.. http://www.access-programmers.co.uk/ubb/wink.gif


Alex

gbanks

I am not clear with what you are trying to do. If your form is already based on EIRReview (I suppose that this is a table???) then you do not need a SQL statment to populate it. Just bound your control to the relevant field.

If not, then your control, based on the SQL statement, is necessarily unbound. I can be used to select data but not to register it in a table! Not without code in the after update event. What would be anyway the point in registering this value in another table? Wouldn t this be data duplication?

In other words, I agree 100% with Pat that there is probably a concept problem with what you are trying to do. Alias, I advise you to follow her indications, she is among the most knowledgeable persons lurking around this forum. http://www.access-programmers.co.uk/ubb/smile.gif


Alex

[This message has been edited by Alexandre (edited 09-17-2001).]

Pat Hartman
09-18-2001, 12:56 PM
Alexandre,
You can use a query or an SQL statement as the RecordSource for a form or as the RowSource for a combo or list box but NOT as the ControlSource for a textbox. The ControlSource of a textbox is designed to handle a single field value - either a column from the form's RecorsSource or a value calculated by an expression. It cannot handle a recordset which is a different type of object.

Alexandre
09-18-2001, 01:11 PM
Ok, Pat
Thanks for the insight.

Alex