To display the result of sql statement on the screen

aman

Registered User.
Local time
Yesterday, 21:53
Joined
Oct 16, 2008
Messages
1,251
Hi All

I want to write VBA code that will use SELECT STATEMENT to fetche data from a table and display the result on the screen when I click on a command button . Could anyone help me to do this.

Regards
Aman
 
i would suggest the following:

create a query on the fly using the sql then open it.

try puttin this code in yr command button:

Dim strSQL As String
Dim qdf As QueryDef
'Assign your select statement strSQL

'Delete qryTemp if it exists
If DCount("Name", "MSysObjects", "Name = 'qryTemp' AND Type = 5") > 0 Then
DoCmd.DeleteObject acQuery, "qryTemp"
End If
'Create a new query based on strSQL called qryTemp
Set qdf = CurrentDb.CreateQueryDef("qryTemp", strSQL)
DoCmd.OpenQuery "qryTemp", acViewNormal
Set qdf = Nothing



wat this does is, firstly deletes qryTemp if it exists, then creates qryTemp using yr sql statement and opens it.
remember to assign the yr statement the strSQL
 
Hi Husan

Thanks a lot..Its working fine...cheers
 

Users who are viewing this thread

Back
Top Bottom