VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Access ODBC DB using SQL and a Data Control

by Scott Lewis (1 Submission)
Category: Databases/Data Access/DAO/ADO
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (6 Votes)

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

Assumes
Create a new form with a DBGrid and a Data Control. Set the datasource property on the grid to use the data control. Set the DB name property on the data control to whatever DB you set up in the ODBC applet on control panel. Set the DB type property to Use ODBC. Set Visible to false.

Rate Access ODBC DB using SQL and a Data Control

'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.

Download this snippet    Add to My Saved Code

Access ODBC DB using SQL and a Data Control Comments

No comments have been posted about Access ODBC DB using SQL and a Data Control. Why not be the first to post a comment about Access ODBC DB using SQL and a Data Control.

Post your comment

Subject:
Message:
0/1000 characters