dcsimg
Results 1 to 9 of 9

Thread: Search/Loop for Database

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    58

    Search/Loop for Database

    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.

    With adoSearch.Recordset
    .MoveFirst
    .Find "ID = '" & Access1.Text & "'"

    If Not .EOF Then
    If ![Password] = Access2.Text Then
    gstrEmpID = Access1.Text
    frmMain.Show
    Unload Me
    Exit Sub
    End If
    End If
    End With

  2. #2
    Fanatic Member kaffenils's Avatar
    Join Date
    Apr 2004
    Location
    Norway
    Posts
    946

    Re: Search/Loop for Database

    is the adoSearch.Recordset object initialized? Make sure that it is an instance of an object in the Locals Window.

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    58

    Re: Search/Loop for Database

    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?
    Attached Images Attached Images  

  4. #4
    Fanatic Member kaffenils's Avatar
    Join Date
    Apr 2004
    Location
    Norway
    Posts
    946

    Re: Search/Loop for Database

    I have never used the ADODC control. I use ADODB and populate controls, execute searches, update, insert etc. manually.

    I'm afraid I can't help you with this, but hopefully somebody else can

  5. #5

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    58

    Re: Search/Loop for Database

    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.

  6. #6
    Fanatic Member kaffenils's Avatar
    Join Date
    Apr 2004
    Location
    Norway
    Posts
    946

    Re: Search/Loop for Database

    The basics of ADO in VB:

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

    Keep in mind that is is just the very basics of ADO. You can more information here http://msdn.microsoft.com/library/de...jparameter.asp
    Attached Files Attached Files
    Last edited by kaffenils; Jan 3rd, 2006 at 01:56 PM.

  7. #7
    Fanatic Member space_monkey's Avatar
    Join Date
    Apr 2005
    Location
    神と歩くこと
    Posts
    573

    Re: Search/Loop for Database

    There's also a really good tutorial written by beacon here.
    Using VB6 or VB.net 2008 with .net 3.5
    "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

  8. #8

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    58

    Re: Search/Loop for Database

    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?

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,171

    Re: Search/Loop for Database

    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

    I believe Beacons tutorial explains this nicely.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width