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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word and query in Access

Status
Not open for further replies.

pfrenn

Technical User
Joined
Mar 22, 2003
Messages
1
Location
SE
Hi,
I am trying to run a query in an access DB from word VBA code.

This is what I am trying to do:
1. From a userform extract values from two drop down lists.
2. Use these values to find a specific record in a database
3. From that record get a value from a specific field and use it in the VBA code again.

I am confused about how to do this and have found CreateQueryDef, but am not sure it is correct to use it.

Confusions:
1. How do I search properly in the database (SQL, seek, find etc statements)
2. How do I set the pointer to THE found record?
3. How do I present the value back in word VBA?
4. If you have any good tips, hints and code I am most greatful!

Have a sunny day!
/Per

This is the code I have been "fiddling with" but it does not work for sure ;-)! (PS! I am Swedish so there might be some strange words here and there)

Sub test_of_query()
'Typ av CV som skall inkluderas

Dim dbJob As database
Dim rstTemp As Recordset
Dim strSQL As String


Set dbJob = OpenDatabase Name:=ActiveDocument.AttachedTemplate.Path + "\job.mdb")
' Open recordsets from the Definitioner table
Set rstDefinitions = dbJob.OpenRecordset("Definitioner", dbOpenDynaset)
'Set qdfDefinitioner = dbJob.CreateQueryDef(
'"TestOfQueryDef", "SELECT * FROM Defintioner WHERE Language =" + ComboBox1.Value + " AND Competency = " + ComboBox2.Value) 'This code is delimited and is the final code I will try to use, but I am running a trial below

strSQL = "SELECT * FROM Defintioner WHERE Language = English AND Competency = Project Management"
Set rstTemp = dbJob.OpenRecordset(strSQL)

Debug.Print rstTemp

dbJob.Close

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top