Link to home
Start Free TrialLog in
Avatar of bolox
bolox

asked on

VERY EASY QUESTION

i havent used VB is ages and have lost all of my prev proggies....

here is my code.....

Dim myconn
Set myconn = New ADODB.Connection
myconn.Open "DBQ=C:\farebase\farebase.mdb;Driver={Microsoft Access Driver (*.mdb)};DriverId=281;FIL=MS Access;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Threads=3;UID=admin;UserCommitSync=Yes;"

Set myado = myconn.Execute("SELECT farebase.* From farebase;")
myado.AddNew
myado!airline = "GazzaAir"
     
myado.Update


when this button is clicked , it says that this recordset does not support updating??

Help what have i done wrong, i think it is to do with lockpesamistic or somehting like that but i cannot find my book

Thanx

My name is Bolox for a reason
Avatar of rpai
rpai

The returned Recordset object is always a READ-ONLY, FORWARD cursor. If you need a Recordset object with more functionality, first create a Recordset object with the desired property settings, then use the Recordset object's Open method to execute the query and return the desired cursor type.

recordset.Open Source, ActiveConnection, CursorType, LockType, Options

recordset.Open "SELECT farebase.* From farebase;", myconn, adOpenDynamic, adLockOptimistic, Options

Hope this helps.
The .Execute method of a connection object returns a read-only recordset. You should use a recordset object or use an Update statement in the execute method:

Dim myconn As ADODB.Connection
Dim myADO As ADODB.Recordset
Set myconn = New ADODB.Connection
Ser myADO = New ADODB.Recordset
myconn.Open "DBQ=C:\farebase\farebase.mdb;Driver={Microsoft Access Driver (*.mdb)};DriverId=281;FIL=MS
Access;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Threads=3;UID=admin;UserCommitSync=Yes;"

myADO.Open "SElect Farebase.* From Farebase",myconn,adOpenStatic,adLockOptimistic
myado.AddNew
myado!airline = "GazzaAir"
   
myado.Update

'Or

myConn.Execute "Insert Into Farebase (airline) Values('GazzaAir')"
Should be ::
recordset.Open "SELECT farebase.* From farebase;", myconn, adOpenDynamic, adLockOptimistic
Avatar of bolox

ASKER

everyone has an opinion  but i cannot get any to work.

sorry to be a pain i am really "BOLOX!"

(i can use ADODC fine by entering manually) but i want to hard code as i have a lot of complex** methods to include

(**complex in my terms means easy to you)

all i want in the end is in my database, in the root of the coding folder (C:\farebase) is for example a text box called text1.text to go into the database,

Table called: farebase and the field called aircode

Thankyou


What errors do you get? It could be that the table structure does not allow the insert because you have a primary key for which you are not supplying a value or that you have other required fields without default values that are also not being supplied. The methods shown work in principle but without knowing the errors you get or the structure of the table/database it is impossible to give a more precise answer at this time.
Avatar of bolox

ASKER

ahhhh, i do have a pri key.

if i use tim's method is comes up with type mismatch on the line.......

Ser myADO = New ADODB.Recordset

?

Then declare myADO As ADODB.Recordset

If you have it declared as

Dim myADO As Recordset

Then this will cause a type mismatch as this is in fact a DAO.Recordset class which is not the same thing at all. If you are declaring objects you MUST ensure that you fully qualify them when you have both DAO and ADO libraries referenced in the project. (either implicitly by including certain controls or explicitly).
Avatar of bolox

ASKER

object or block variuable not set error now.??

refering this line

myADO.Open "SElect Farebase.* From Farebase", myconn, adOpenStatic, adLockOptimistic


just to recap, my button code is:

Private Sub Command4_Click()


Dim myconn As ADODB.Connection
Dim myADO As ADODB.Recordset
Set myconn = New ADODB.Connection
Ser myADO = New ADODB.Recordset
myconn.Open "DBQ=C:\farebase\farebase.mdb;Driver={Microsoft Access Driver (*.mdb)};DriverId=281;FIL=MS Access;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Threads=3;UID=admin;UserCommitSync=Yes;"

myADO.Open "SElect Farebase.* From Farebase", myconn, adOpenStatic, adLockOptimistic
myADO.AddNew
myADO!airline = "GazzaAir"
   
myADO.Update
   
End Sub

what do i put in the top::: genreal declarations section?







Avatar of bolox

ASKER

as i am messing you all around, more points are being added, sory for being soooo think
Avatar of bolox

ASKER

i mean thick (DUH!!)
Avatar of Richie_Simonetti
Are you referencind ADO and DAO at same time?
If so, you need to explicitly create declarations objects with full name, for instance

'DAO
dim myrs as DAO.recordset

'ADO
dim myrs as ADOBD.recordset
ASKER CERTIFIED SOLUTION
Avatar of mdougan
mdougan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>object or block variuable not set error now.??
>refering this line
>myADO.Open "SElect Farebase.* From Farebase", myconn, adOpenStatic, adLockOptimistic

>Ser myADO = New ADODB.Recordset

Shouldn't this be

SET myADO = New ADODB.Recordset

Rest of the code looks fine.
if the highlighed code when the error pops up is:

adOpenStatic, adLockOptimistic

then you need to go into your project references and add

Microsoft Active Data Objects...
How about adding this code before opening your recordset

'try setting the cursorlocation (sometimes not setting     this gives a problem)

rs.CursorLocation=aduseClient
rs.Open "Select Farebase.* From Farebase", myconn, adOpenDynamic, adLockOptimistic

--where "rs" is your Recordset. Hope this helps!


 
Avatar of bolox

ASKER

thanx for that. spot on.

Thankyou to everyone else also, do not worry i will be in and out of here all day today. i have loads more questions for ya coming up

(easy also)