473,395 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Make a simple select query

stephane
how?
i need get some data from table, at the action
i try anything DAO and ADO, it doesn't works((

for example, this code
Expand|Select|Wrap|Line Numbers
  1. Dim WorkBase as Database 
  2. Dim WorkRS1 as Recordset 
  3. Dim SQL as String 
  4.  
  5. Set WorkBase = OpenDataBase(“voyages.mdb”) 
  6.  
  7. SQL = “Select init from Managers WHERE contact=” & manager 
  8. Set WorkRS1 = WorkBase.OpenRecordset(SQL) 
  9.  
  10. WorkRS1.Close 
  11. WorkBase.Close
  12.  
it returns error at the first line Dim WorkBase as Database
"User-defined type not defined"

what's wrong?
help me pls
Feb 15 '07 #1
6 2375
MMcCarthy
14,534 Expert Mod 8TB
how?
i need get some data from table, at the action
i try anything DAO and ADO, it doesn't works((

for example, this code
Expand|Select|Wrap|Line Numbers
  1. Dim WorkBase as Database 
  2. Dim WorkRS1 as Recordset 
  3. Dim SQL as String 
  4.  
  5. Set WorkBase = OpenDataBase(“voyages.mdb”) 
  6.  
  7. SQL = “Select init from Managers WHERE contact=” & manager 
  8. Set WorkRS1 = WorkBase.OpenRecordset(SQL) 
  9.  
  10. WorkRS1.Close 
  11. WorkBase.Close
  12.  
it returns error at the first line Dim WorkBase as Database
"User-defined type not defined"

what's wrong?
help me pls
In the VBA Editor check Tools - References. Make sure there is a DAO library ticked on the list.

Mary
Feb 15 '07 #2
i turn on it,
now, other error at line
Set WorkRS1 = WorkBase.OpenRecordset(SQL)
"Runtime error 13, Type Mismatch"
Feb 15 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
If manager is a control on your form and a text data type, try ...

Expand|Select|Wrap|Line Numbers
  1. SQL = "Select init from Managers WHERE contact='" & manager & "'"
Mary
Feb 15 '07 #4
ADezii
8,834 Expert 8TB
how?
i need get some data from table, at the action
i try anything DAO and ADO, it doesn't works((

for example, this code
Expand|Select|Wrap|Line Numbers
  1. Dim WorkBase as Database 
  2. Dim WorkRS1 as Recordset 
  3. Dim SQL as String 
  4.  
  5. Set WorkBase = OpenDataBase(“voyages.mdb”) 
  6.  
  7. SQL = “Select init from Managers WHERE contact=” & manager 
  8. Set WorkRS1 = WorkBase.OpenRecordset(SQL) 
  9.  
  10. WorkRS1.Close 
  11. WorkBase.Close
  12.  
it returns error at the first line Dim WorkBase as Database
"User-defined type not defined"

what's wrong?
help me pls
Here is workable code that Opens an External Database (C:\Test\Test.mdb), creates a Recordset based on a simple SQL Statement, then loops through all Records in the Recordset outputting the First and Last Name Fields to the Immediate Window.
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database, MyWks As DAO.Workspace
  2. Dim MyRS As DAO.Recordset, strSQL As String
  3.  
  4. strSQL = "SELECT * FROM tblEmployee;"
  5.  
  6. Set MyWks = CreateWorkspace("", "admin", "", dbUseJet)
  7. Set MyDB = MyWks.OpenDatabase("C:\Test\Test.mdb", True)     'Open Exclusive
  8. Set MyRS = MyDB.OpenRecordset(strSQL, dbOpenDynaset)
  9.  
  10. Do While Not MyRS.EOF
  11.   Debug.Print MyRS![FirstName] & " " & MyRS![LastName]
  12.   MyRS.MoveNext
  13. Loop
  14.  
  15. MyRS.Close
  16. MyDB.Close
  17. MyWks.Close
Feb 16 '07 #5
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database, MyWks As DAO.Workspace
  2. Dim MyRS As DAO.Recordset, strSQL As String
  3.  
  4. strSQL = "SELECT * FROM tblEmployee;"
  5.  
  6. Set MyWks = CreateWorkspace("", "admin", "", dbUseJet)
  7. Set MyDB = MyWks.OpenDatabase("C:\Test\Test.mdb", True)     'Open Exclusive
  8. Set MyRS = MyDB.OpenRecordset(strSQL, dbOpenDynaset)
  9.  
  10. Do While Not MyRS.EOF
  11.   Debug.Print MyRS![FirstName] & " " & MyRS![LastName]
  12.   MyRS.MoveNext
  13. Loop
  14.  
  15. MyRS.Close
  16. MyDB.Close
  17. MyWks.Close
thanks, this code is works.
i think the reason of error was at the dbOpenDynaset key. i don't assign it to function befor
Feb 16 '07 #6
ADezii
8,834 Expert 8TB
thanks, this code is works.
i think the reason of error was at the dbOpenDynaset key. i don't assign it to function befor
The reason why it didn't work before was probably because this line was omitted from the code. You must create a Workspace Object to open a Database within:
Expand|Select|Wrap|Line Numbers
  1. Set MyWks = CreateWorkspace("", "admin", "", dbUseJet)
Feb 16 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: unixman | last post by:
As usual, it is 2:00am, and I'm pulling my hair out, finally resorting to posting in the newsgroups for help. :) Simple problem, in theory. Given table "map": CREATE TABLE map ( entry_id...
6
by: Eddie Smit | last post by:
field- field- surname town ---- ---- john NY john Vegas john Boston eddie Boston eddie New Orleans eddie NY
7
by: Nicolae Fieraru | last post by:
I have two tables, they contain: Table1: ID1, Name1, Address1, Purchase1 Table2: ID2, Name2, Address2, Purchase2 I need a query which creates Table3 with content from Table1 and Table2. The...
7
by: rednexgfx_k | last post by:
All, Problem Summary: I've running about 30 make table queries via VBA in Access 2000, and my database goes from 14,000k to over 2,000,000k. In addition, the longer the procedure runs, the...
24
by: Bob Alston | last post by:
Anyone know a way to make all access to a linked table, in another Access MDB, read only? I really don't want all the hassle of implementing full access security. I can't do this at the server...
3
by: John Baker | last post by:
Hi:7 Newby here to ASP, and using the ASP.NET Web Matrix development tool. While that tool looks great for a Newby, I have run into a snag. I have an HTML Text Box which I have named HireInput,...
7
by: Ivan Marsh | last post by:
Hey Folks, I'm having a heck of a time wrapping mind around AJAX. Anyone know of a simple, straight-forward example for pulling a simple query from mysql with PHP using AJAX? As I...
27
by: MLH | last post by:
How can I turn the following into a make-table query? SELECT & " " & AS Recipient FROM tblVehicleJobs INNER JOIN tblAddnlOwnrs ON tblVehicleJobs.VehicleJobID = tblAddnlOwnrs.VehicleJobID WHERE...
5
by: lsllcm | last post by:
Hi All, I have one question about many "or" operation make system choose incorrect index There is one table TT ( C1 VARCHAR(15) NOT NULL, C2 VARCHAR(15) NOT NULL, C3 VARCHAR(15) NOT NULL,...
3
by: Ken Fine | last post by:
This is a question that someone familiar with ASP.NET and ADO.NET DataSets and DataTables should be able to answer fairly easily. The basic question is how I can efficiently match data from one...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.