Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access with SQL 2

Status
Not open for further replies.

dcomit

Technical User
Jun 20, 2001
115
GB
I'm not a programmerbu I'm sure this is simple stuff to all you boffins out there.

What I want to do is to open an Access database, generate an SQL query, display the results and close the database.

Can anyboby point me to some simple VB code to allow me to do this?
 
Do you want to do this from a Visual Basic form? How do you want to display the data? Text Boxes? A Grid? I have a boatload of routines that will do this, providing I know how you want it done.
 
Hackster,

I actually want to do this in VBA from a Word 97 macro and pass the results into a document. Is this possible.

D.
 
I have no idea. I've never used VBA. I've always written a program that did what I wanted it to do with whatever Office products I wanted to use. I'm sure that are VBA people out there that can answer your question.
 
Hi there ...

Sure this would be a piece of cake to you experts,

Q1: How to execute an SQL query form VB6 form to retrieve the data in .mdb file (that is associated with a DATA control) and damp it into a FlexGrid control?

Q2: I tried to open an Access2000 .mdb file using DATA control but a 'Unrecognized Database Format' message has just pop-up while setting RecordSource property, why?!

Hopeing a responce.
 
Hackster, I would like to open access from VB6 and add data to a table. I am using an ADO connection to my access database. I am viewing my tblCLIENT in a grid and then i have a frmAddClient that has one text box and a cmdAdd button. How do I get what's in the text box to add a row in my tblCLIENT? thanks for the help.
 
Hi elecrta, use the following code:

Private Sub LoadGrid()
Dim wk As Workspace
Dim db As Database
Dim rs As Recordset
Dim sSQL As String
Dim sData As String

Set gWk = CreateWorkspace("Data", "admin", "",dbUseJet)
Set gDb = gWk.OpenDatabase("C:/.../x.mdb, , False)

sSQL = "SELECT name, phone, fax FROM tblCust ORDER BY name"
Set rs = db.OpenRecordset(sSQL, dbopensnapshot)

If rs.RecordCount = 0 Then
FlexGrid.Clear
Else
rs.MoveFirst
FlexGrid.Rows = 1
Do Until rs.EOF = True
sData = "" & Chr$(9)
sData = sData & gRs("name") & Chr$(9)
sData = sData & gRs("phone") & Chr$(9)
sData = sData & gRs("fax") & Chr$(9)

FlexGrid.AddItem sData
rs.MoveNext
Loop
End If

rs.Close
Se rs = Nothing

End Sub



Hi pe!
Try this:

"INSERT INTO tblCLIENT " _
& "(name) VALUES " _
& "('" & Me.txtNAME.Text & "')"



Hope it helps you both


''Life is like a box of chocolate...''
 
I would like to thank you Dzidze for your co-operation.
happy.gif
 
No problem...

Just hope it helped you get through ''Life is like a box of chocolate...''
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top