VB icon

Access ODBC DB using SQL and a Data Control

Email
Submitted on: 1/3/2015 8:34:00 PM
By: Scott Lewis (from psc cd)  
Level: Not Given
User Rating: By 6 Users
Compatibility: VB 5.0, VB 6.0
Views: 1072
 
     This code will allow you to populate DBGrids and other bound data controls using a Data Control, SQL, and an ODBC DataBase.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Access ODBC DB using SQL and a Data Control
' Description:This code will allow you to populate DBGrids and other bound data controls using a Data Control, SQL, and an ODBC DataBase.
' By: Scott Lewis (from psc cd)
'
' 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.
'**************************************

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


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.