Hi, I would like to ask if there is any problem with my coding because when i run it gave me an error saying object variable or With block variable not set. Then when i click debug it take me to the .movefirst. It's my coding something wrong? Can someone help me out? Thanks.
well...i see other people doing the adosearch without putting the adodc1 scroll bar thingy. I wonder how they get it work without putting the adodc1 scroll bar. Anyhow I have already initialized the adosearch.recordset. Let me show you the picture. Is that how u initialized the adosearch.recordset?
but can you teach me set the adodb manually as i m curious to know how they r connected to it without using the ADODC control. I've tried to figure it out but i couldn't understand the connection. Sorry, I'm not a programming sudent though but I have a little knowledge on the basic side of visual basic. Just want to learn more about it. Thank you.
- First of all you must create a reference in VB to Microsoft ActiveX Data Object 2.X library. Version 2.8 is the latest, so you it if you find it. If you don't have it, you can download it from http://www.microsoft.com/downloads/d...DisplayLang=en.
The most used ADODB objects are the Connection, Command, Parameter and Recordset.
The first thing you should do is to create a connection to the database. The Connenction object requires a connection string. The content of this string depends on which database you want to connect to. You can find the most common connection strings at http://www.connectionstrings.com/.
I'm not sure what database you are using, but let's assume it is an Access database. The connection string will then look something like this: "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;User Id=admin;Password=;"
When you have opened a connection you can use the Command or Recordset to execute SQL statements. That can be SELECT, DELETE, UPDATE, INSERT, CREATE TABLE, ALTER TABLE etc. etc.
The recordset object is usually used to retrieve data from tables or views/queries while the Command object is used to execute the rest of the SQL statements, but you can use the Command object to execute SELECT statements aswell. The Command object also support Parameters.
I have attached a little demo that opens a connection to an Access database and performs a search in the Users table. The search can be performed using a Recordset object or a Command object.
well kaffenils, your example that you show me is much complicated than it seems to me. I'll have lotsa question to ask you though. =)
Dim lvw As ListView <---what is this?
Dim litem As ListItem <---what is this?
Dim conn As ADODB.Connection <---just like ADODB controls right ?
Dim rs As ADODB.Recordset <---just like ADODB controls right ?
Set lvw = Me.ListView1 <---what is this?
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset <-this is to set your connection to database right?
Dim lvw As ListView <---what is this?
Dim litem As ListItem <---what is this?
This is declaring the variable lvw as a ListView control, and litem as a item within a ListView.
Dim conn As ADODB.Connection <---just like ADODB controls right ?
Dim rs As ADODB.Recordset <---just like ADODB controls right ?
Basically like ADODC controls. conn is the connection to the database, and rs is a set of data. Unlike with ADODC, you only need one connection, no matter how many recordsets you have.
Set lvw = Me.ListView1 <---what is this?
This sets the variable to an instance of a control (anything you do to the variable affects the control).
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset <-this is to set your connection to database right?
Not quite, this is just setting up the variables - typically the connection is set up using conn.open