 |
(Pages: 1 2 ) |
 |
noknok Level: Big Cheese
 Registered: 23-11-2007 Posts: 20
|
Find record, multiple result
Im Using ADO need help making a Find Record in my database access
Const DBPATH = "C:bio\medata.mdb"
Dim cn As New ADODB.Connection, rs As ADODB.Recordset
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBPATH
rs.Source = "biodata"
rs.Open , cn
Dim myname As String
searchlist.Clear
If myname = "" Then
InputBox (UCase("please type the name you are looking"))
search.searchlist.AddItem (rs("lname") & "" & "," & rs("fname") & "")
rs.MoveFirst
End If
help thanks
|
|
28-12-2007 at 03:42 AM |
|
|
noknok Level: Big Cheese
 Registered: 23-11-2007 Posts: 20
|
Re: Find record, multiple result
when i use that code i received error
Runtime error 91
Object variable or with block variable not set
and when i click debug to find out it trigers to
rs.Source = "biodata"
I dont know what to do,,
by the way if i use Select what should i do
|
|
02-01-2008 at 07:54 AM |
|
|
yronium Level: Moderator

 Registered: 14-04-2002 Posts: 930
|
Re: Find record, multiple result
Hello. You didn't paste all the code kieron have posted to you, did you?
quote: noknok wrote:
Dim ..... , rs As ADODB.Recordset
' [....]
rs.Source = "biodata" |
If you declare an object variable (your rs variable here) you just allocate the memory space, but you didn't really create it until you use the Set instruction. Once you have Set the variable onto an existing ADODB.Recordset or onto a New ADODB.Recordset, the recordset variable actually exists and you are allowed to set its Source property. If you try before, it raises the error you got: "Object variable not set".
With your cn variable you have used the implicit creation (not recommended) by the "Dim cn As New ..." declaration formula, but you didn't with the rs variable (I argue you missed the New keyword). So you have to create later (recommended procedure) the recordset variable with the explicit creation instruction: "Set rs = New ADODB.Recordset" before trying to set its Source property. But notice that though the new recordset creation is the most used option, you could rather need to set the rs variable on an existing open/closed recordset object, like "Set rs = MyPreviousRs".
I guess you copied somebody's else code without deeply knowing every instruction, so I also argue you were not intended to set the recordset variable onto another previously open recordset of yours, but instead you would have wanted to do something like following: ' only reserve the memory space for the further variables
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
' actually creates the Connection variable
Set cn = New ADODB.Connection
' open the connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBPATH
' actually creates the recordset object
Set rs = New ADODB.Recordset
' set recordset's source property
rs.Source = "biodata"
' [... other code...] | Please notice that I did the recommended explicit procedure with the Connection variable too.
Hope it helps.
____________________________
Real Programmer can count up to 1024 on his fingers
|
|
02-01-2008 at 02:27 PM |
|
|
noknok Level: Big Cheese
 Registered: 23-11-2007 Posts: 20
|
Re: Find record, multiple result
yronium actually sort of it i copied some of my code according to my research in some newbie guide visual basic and there's a lot of find method approach so it comes out that i have to make the expeirmentation so suddenly that was the out put, ^^ anyway thanks for the explanation yronium i really apriciate it and to stickleprojects and currently got confuse with the ado dao lols kinda ________ hehehe anyway ill try the sugest of you two thanks,
T_T i realy dont get it why i got error object requierd when pres debug trigers to filter.on
[Edited by noknok on 03-01-2008 at 12:34 AM GMT]
|
|
03-01-2008 at 12:05 AM |
|
|
noknok Level: Big Cheese
 Registered: 23-11-2007 Posts: 20
|
Re: Find record, multiple result
im realy realy confuse ^^ im geting pissed dont know the code to put lols first i did put a name in a searchlist but it display all the name of person, and now i seen lots of code T_T and approach,
when finding a record in a database
first declare the connection
dim blablah as new adodb.connection, dim next as new adodb.recordset
2nd must declare the connection provider
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBPATH
and declare some
dim myname as string to use in finding record
now what im going to do in this next step T_T
why others use select
and other use adodc.blablah.recordset
im getting confuse
can u guys explain it again to me thanks
because i dont realy get it thanks again
|
|
03-01-2008 at 12:51 AM |
|
|
noknok Level: Big Cheese
 Registered: 23-11-2007 Posts: 20
|
Re: Find record, multiple result
quote: stickleprojects wrote:
Hi
rs.filteron = true not rs.filter.on.
does that help?
i try that already and i got error
method or data mamber not found
so i use rs.filter.on = true
and anyway i dont know what does filter purpose is i just read it and dont even get in my mind ^^
|
|
03-01-2008 at 12:55 AM |
|
|
noknok Level: Big Cheese
 Registered: 23-11-2007 Posts: 20
|
Re: Find record, multiple result
Btw i put a public declaration to a module
in my module i put this one
Public const dbpath = "c:\bio\biodata.mdb"
is this affect my code in the form badly
i notice that when i change that dbpath into Ucase
then in my dbpath in form change to ucase also
geze
^^ thanks for the tip and help kieron i owe u a lot
|
|
04-01-2008 at 12:15 AM |
|
|
noknok Level: Big Cheese
 Registered: 23-11-2007 Posts: 20
|
Re: Find record, multiple result
Public Sub OpenDB()
Dim dbpath As String
dbpath = App.Path & "\" & DBNAME
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath
End Sub
i don't get this one
dbpath = App.Path & "\" & DBNAME <---- i dont get what does it mean
dbpath as string and use for dbpath = App.Path & "\" & DBNAME
ps will while ago i try the search query as u sample it, dbpath = App.path & "\" & DBNAME <-- meaning that u dont need to specify like const dbpath =C:\biotest\biodata.mdb
am i corect sir,
and i have problem with the filter im still making on it how to work it out,
and i come out with another question how can i put a string that to inform the user that the existing Lasname or name of person does not exist.
thanks
[Edited by noknok on 04-01-2008 at 05:43 AM GMT]
|
|
04-01-2008 at 03:34 AM |
|
|
stickleprojects Level: Moderator

 Registered: 09-09-2002 Posts: 971
|
Re: Find record, multiple result
Hi,
Dim dbpath As String ' declare memory space for the full path to the mdb
dbpath = App.Path & "\" & DBNAME ' construct the path based on the location of this VBP (or EXE file)
' if DBNAME is a full path, then change to
' dbpath=DBNAME
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath
|
Hope that's clearer. I assumed that the MDB would be in the same folder as the VBP, so yes, you are correct if DBPATH contains the full path, you don't need to use app.path (don't forget our quotes around the path!)
What's the problem with the filter? The VBP i sent you applies the filter 2 different ways, you can choose.
If no records, the rs.eof will be true before you movenext. As in..
if rs.eof then
msgbox "None found"
else
' Loop through the found records
Do While Not rs.EOF
' add item to the list
searchlist.AddItem (rs("lname") & "" & "," & rs("fname") & "")
' move to next record
rs.MoveNext
' jump to the dowhile bit
Loop
end if
|
Hope that helps
Kieron
____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)
|
|
04-01-2008 at 08:18 AM |
|
|
noknok Level: Big Cheese
 Registered: 23-11-2007 Posts: 20
|
Re: Find record, multiple result
hey im back again ^^ thanks for the nice code kieron but stil i dont know why the rs.filter wont work
regarding with the
set rs = rs.execute(select * from blah blah ) <-- how this thing work select was from sql right so i see the example why it goes like that plss be guided me thanks. im expecting also reply of mr yronium ^^
[Edited by noknok on 11-01-2008 at 07:43 AM GMT]
|
|
11-01-2008 at 07:42 AM |
|
|
yronium Level: Moderator

 Registered: 14-04-2002 Posts: 930
|
Re: Find record, multiple result
Hello noknok.
The Execute method is an ADODB.Connection's method, not a Recordset object's method. So your instruction "set rs = rs.execute(select * from blah blah )" is wrong: it had to be "set rs = cn.execute(select ...)" instead.
But though you can retrieve an entire recordset as an Execute method result, this is not the best way to do it: rather, you should open a recordset object. The recordset you retrieve by an Execute method is a read-only client-side keyset recordset (...er, I'm not sure at the moment if these are the correct defaults, and I have no books here, sorry...), so you can't customize it. If you use Recordset object's Open method instead you can set its properties before opening in order to obtain a recordset that's better fit for your purposes.
There are plenty of sample code in the internet, and in this forum too (click the Search link above), but I post a sample code to you: ' assume that cn is an open ADODB.Connection object
Dim rs As ADODB.Recordset
Dim sql As String
sql = "SELECT * FROM biodata"
Set rs = New ADODB.Recordset
rs.Open sql, cn, adOpenForwardOnly, adLockReadOnly, adCmdText | When you open a recordset with this technique you can customize every recordset's property before opening, moreover the lock type, the cache size, the cursor location (not relevant with MSJet), the cursor type, and so on.
Once you have open the recordset, you can set its Filter property according to your purposes, like following| rs.Filter = "lname = " & Chr(39) & myname & Chr(39) | You already know how to manage the Filter property, and you can find more details in this page, but if you have to show only those specific records during the entire recordset lifetime you might want to consider opening the already filtered recordset (it seems to me that stickleproject already told it to you once) opening it with an appropriate sql instruction like following:' assume that cn is an open ADODB.Connection object
Dim rs As ADODB.Recordset
Dim sql As String
sql = "SELECT * FROM biodata"
sql = sql & " WHERE lname = "
sql = sql & Chr(39) & myname & Chr(39)
Set rs = New ADODB.Recordset
rs.Open sql, cn, adOpenForwardOnly, adLockReadOnly, adCmdText | This technique has the advantage of leaving the DBMS the filtering job: when using a large network server-client database this method can reduce the network data flow, with better performances. And usually a network server is a more performant machine, so it can execute queries faster than the client. Unfortunately these advantages don't apply to Access/Jet based systems, but the query execution is anyway a bit faster due to the more specialized and less busy Access' engine.
This is only a suggestion, and has nothing to do with your error (the "rs.Execute" wrong line) but you should consider to improve your technique.
Hope it helps.
____________________________
Real Programmer can count up to 1024 on his fingers
|
|
11-01-2008 at 10:40 AM |
|
|
noknok Level: Big Cheese
 Registered: 23-11-2007 Posts: 20
|
Re: Find record, multiple result
hello tthanks
kieron i found my error and its works fine now ^^ thanks to you, 2 days to find out why lols, i understand little bit the rs.filter thing, but not that broad im still searching the other site for more example about the filter
and yroniumi im still reading it 3 times and its not getting in my head ^^ anyway im still studying it.
and one more thing about the kieron code i try to expirement it in module why its not working ill post it tomorow the error im not in my computer now im in school now and my thought on my computer about the code why it 's not working ^^
when you put it in the module the module will be read first right? before the form will be run am i right?
so i did code the ff:
in module
option explicit
Public Const DBNAME ="biotada.mdb"
' next i put
Public Sub OpenDB()
Dim dbpath As String
dbpath = App.Path & "\" & DBNAME
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&_ dbpath
end sub
' in my search form
Dim rs As Recordset
Dim myname as string
myname = Inputbox(" Enter Name Here")
set rs = new Recordset
rs.Open "Select * from biodata where lname like'" & myname _ & "%'", cn
searchlis.clear
Do while Not rs.EOF
searchlist.additem (rs("lname") & "" & "," & rs("fname") & "")
rs.movenext
loop
rs.close
set rs= nothing
this all the code i put so whats the problem i got error or my coding is wrong
when declare public u can use it anytime right ?
[Edited by noknok on 12-01-2008 at 10:02 AM GMT]
|
|
12-01-2008 at 09:58 AM |
|
|
noknok Level: Big Cheese
 Registered: 23-11-2007 Posts: 20
|
Re: Find record, multiple result
here i am again stil dont know
this are the code i create
' in my module
Public Const DBNAME = "biodata.mdb"
Public Sub Opendb(db)
Dim DBPATH As String
DBPATH = App.Path & "\" & DBNAME
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBPATH
End Sub
'in my search box
Private Sub infocmd_Click()
Dim myname As String
Dim rs As Recordset
myname = InputBox("Please Type The Name Here")
Set rs = New Recordset
rs.Open "Select * from biodata where lname like '" & myname & "%'", cn
searchlist.Clear
Do While Not rs.EOF
searchlist.AddItem (rs("lname") & "" & "," & rs("fname"))
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
End Sub
'and i got the following error
arguments are of the wrong type , are out of acceptable range, or are in conflict with one another
and when i debug it triggers to my
rs.Open "Select * from saudi where lname like '" & myname & "'", cn
please help
[Edited by noknok on 15-01-2008 at 02:50 AM GMT]
|
|
15-01-2008 at 02:48 AM |
|
|
noknok Level: Big Cheese
 Registered: 23-11-2007 Posts: 20
|
Re: Find record, multiple result
yes and its still the same
and one thing is i don't know how to identify the DAO on my coding ^^ hehehe can u help me know that
|
|
15-01-2008 at 07:49 AM |
|
|
noknok Level: Big Cheese
 Registered: 23-11-2007 Posts: 20
|
Re: Find record, multiple result
I dont Get what u Mean ^^ sory im still a student in my reference i already added the Microsoft active object library
or i forgot something else and DAO is old technology right so i started practicing my VB on a Book and A website vbtutor.net and profsr.com and jumpt it here.
what im going to do now?
|
|
16-01-2008 at 12:10 AM |
|
|
yronium Level: Moderator

 Registered: 14-04-2002 Posts: 930
|
Re: Find record, multiple result
Hello noknok. Another test: I notice that into your Jan, 4th post you put the complete mdb filename and path into a constant, but into the next post you build the connection string with the App.Path instruction. So it raises me a doubt: are you specifying the right target for the connection?
Modify your OpenDB function as following: Public Sub OpenDB()
Dim dbpath As String
dbpath = App.Path & "\" & DBNAME
' add these lines to debug
Debug.Print "dbpath: " & dbpath
Debug.Assert False
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath
End Sub | When you run the code, execution stops on the Debug.Assert instruction, so you can read into the Debug window the value of your dbpath variable: check if it actually points to the correct path of you mdb file.
quote: noknok wrote:'and i got the following error
arguments are of the wrong type , are out of acceptable range, or are in conflict with one another
and when i debug it triggers to my
rs.Open "Select * from saudi where lname like '" & myname & "'", cn
The arguments seem to be ok, but in the above code you typed down "Select * from biodata .....". So check what code are you actually passing it, and if the table and field names are correct.
And I suggest you to replace the single quotes in the sql string with the Chr(39) instruction (..."Select * from saudi where lname like " & Chr(39) & myname & Chr(39) ...), that makes the string more readable and prevent usual Access' quotes_into_text_fields problems.
And I also suggest you (again) to build your sql instruction into a separate string variable. With this technique you can verify the variable value into the Debug window, as I've shown above, before passing it to the rs.Open method.
As the arguments seem to be ok, it's relevant that we know if you declared an ADO recordset or a DAO recordset, and the connection object as well. So wherever in your code select the cn object, then hit Shift+F2 to jump to its declaration and post it here.
And finally: post your code. I mean: don't type here what you think you coded, but select your code, hit Ctrl+C, then click here and hit Ctrl+V. When I find different pieces of code, like the above case, I always argue that who posted it has not really pasted what he actually coded. And often the error lies in the part he forgot to paste. So paste your effective code, not a schema of it.
Hope it helps.
[Edited by yronium on 16-01-2008 at 08:43 AM GMT]
____________________________
Real Programmer can count up to 1024 on his fingers
|
|
16-01-2008 at 07:39 AM |
|
|
|
|
 |
 |