VB,Acces,SQL, Data controls or hard code?
Posted on 1997-03-21
I'm trying to create a VB front end for an access database of book titles. I have a text box that accepts SQL code and searchs the Database and displays the correct records in a DB Grid. I would like to be able to run one regular SQL Query
SELECT Titles.[Title] ,Titles.[Year Published] FROM Titles WHERE [Year Published] > YEAR
where year is a differnet value entered in a seperate text box. I guess my immediate question is can I set up this SQL statement in code somewhere instead of entering it in the text box. Then I would like to enter a value (year variable) that would execute my query for that particular year
Private Sub cmdExecute_Click()
On Error GoTo CorrectSQL
Data1.RecordSource = "" & txtSQLCode & ""
On Error GoTo 0
If Err.Number = 3061 Then
nresponse = MsgBox("Check your SQL Code!", vbOKOnly, "Error!")
txtSQLCode.SelStart = 0
txtSQLCode.SelLength = Len(txtSQLCode.Text)
Private Sub cmdQuit_Click()
Private Sub Form_Load()
Data1.DatabaseName = "C:\Program Files\Microsoft Visual Basic\Biblio.MDB"
Data1.RecordsetType = 1
Data1.RecordSource = "Titles"
Private Sub txtSQLCode_Change()
Dim year As Integer
year = 1992
If txtSQLCode <> "" Then
cmdExecute.Enabled = True
Else: cmdExecute.Enabled = False