I have canged the DoCmd to CurrentDb.Execute
That's just two sides of the same coin. The difference between DoCmd.RunSQL and CurrentDb.Execute is that with RunSQL the query will be evaluated by the Access expression service before being passed to the database engine (Ace/Jet), while with CurrentDb.Execute it will be passed directly to Ace/Jet. I prefer the .Execute method because you don't have to code around the Access warning messages. However, they are both for action queries and do not work with select queries, which is what it sounds like you're working with.
If you're going to use an unbound form you could do something like the following. This assumes you're running this from within the form while it is open.
Code:
Dim strSQL As String
strSQL = "Select Field1, Field2, Field3 From SomeTable Where X=Y"
With CurrentDb.OpenRecordset(strSQL)
Me!TextBox1 = !Field1
Me!TextBox2 = !Field2
Me!TextBox3 = !Field3
End With
Or, if you have a saved query that is used as the record source of a form, you can rewrite the sql with QueryDefs;
Code:
Dim qdf As QueryDef
Dim strSQL As String
Set qdf = CurrentDb.QueryDefs("MySavedQuery")
strSQL = "Select Field1, Field2, Field3 From SomeTable Where X=Y"
qdf.SQL = strSQL
Or, if the selected fields for the record source is not going to change, just the criteria, then you can just apply a filter to the form based on certain criteria;
Code:
Me.Filter = "SomeField = SomeValue"
Me.FilterOn = True