Advertisement
2002ASP Databases/ Data Access/ DAO/ ADO #1133

Access ODBC DB using SQL and a Data Control

This code will allow you to populate DBGrids and other bound data controls using a Data Control, SQL, and an ODBC DataBase.

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
'This code assumes a DB with a table named "Appointments" and fields named '"AppName", "AppTime", "Appointment", and "Notes".
'put this into the Form_Load() area of the form the grid and data 
'control are on.
  Data1.RecordSource = ""
  Data1.RecordSource = ReturnFieldsSQL
  Data1.Refresh
  DBGrid1.Refresh
'put this function in a module
Public Function ReturnFieldsSQL()
   Dim SQLS As String
   SQLS = "SELECT AppDate,"
   SQLS = SQLS + " " & "Apptime,"
   SQLS = SQLS + " " & "Appointment,"
   SQLS = SQLS + " " & "Notes"
   SQLS = SQLS + " " & "From [Appointments]"
   ReturnFieldsSQL = SQLS
End Function
'And thats all there is to it.
'This is a very simple function to use.
'You can alter the number of items to return.
'I'm still working on the syntax for the "Where" clause to go with this 'function.
'Once the form loads, if you do it right,
'the grid will be filled with the tables specified here.
Original Comments (3)
Recovered from Wayback Machine