Access with VBA and SQL

Creating Query

 

Option Compare Database

Sub CreateMyQuery()

Dim strSQL As Variant

Dim strVal As Variant

Dim myQuery As QueryDef

On Error Resume Next

DoCmd.DeleteObject acQuery, "NewQuery"

strVal = InputBox("Input Value to be found", "?")

strSQL = "Select * from T1 where Field1 =" & strVal & " OR Field2 =" & strVal & " OR Field3 =" & strVal & " OR Field4 =" & strVal & " OR Field5 =" & strVal

Set myQuery = CurrentDb.CreateQueryDef("NewQuery", strSQL)

DoCmd.OpenQuery myQuery.Name

myQuery.Close

Set myQuery = Nothing

End Sub

© 2013-2024 PRV.pl
Strona zostaƂa stworzona kreatorem stron w serwisie PRV.pl