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 ={Microsof t Access Driver (*.mdb)};DriverId=281;FIL= MS Access;MaxBufferSize=2048; MaxScanRow s=8;PageTi meout=5;Sa feTransact ions=0;Thr eads=3;UID =admin;Use rCommitSyn c=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
here is my code.....
Dim myconn
Set myconn = New ADODB.Connection
myconn.Open "DBQ=C:\farebase\farebase.
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
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 ={Microsof t Access Driver (*.mdb)};DriverId=281;FIL= MS
Access;MaxBufferSize=2048; MaxScanRow s=8;PageTi meout=5;Sa feTransact ions=0;Thr eads=3;UID =admin;Use rCommitSyn c=Yes;"
myADO.Open "SElect Farebase.* From Farebase",myconn,adOpenSta tic,adLock Optimistic
myado.AddNew
myado!airline = "GazzaAir"
myado.Update
'Or
myConn.Execute "Insert Into Farebase (airline) Values('GazzaAir')"
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.
Access;MaxBufferSize=2048;
myADO.Open "SElect Farebase.* From Farebase",myconn,adOpenSta
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
recordset.Open "SELECT farebase.* From farebase;", myconn, adOpenDynamic, adLockOptimistic
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
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.
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
?
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).
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).
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 ={Microsof t Access Driver (*.mdb)};DriverId=281;FIL= MS Access;MaxBufferSize=2048; MaxScanRow s=8;PageTi meout=5;Sa feTransact ions=0;Thr eads=3;UID =admin;Use rCommitSyn c=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?
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.
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?
ASKER
as i am messing you all around, more points are being added, sory for being soooo think
ASKER
i mean thick (DUH!!)
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>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.
>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...
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=aduseCli ent
rs.Open "Select Farebase.* From Farebase", myconn, adOpenDynamic, adLockOptimistic
--where "rs" is your Recordset. Hope this helps!
'try setting the cursorlocation (sometimes not setting this gives a problem)
rs.CursorLocation=aduseCli
rs.Open "Select Farebase.* From Farebase", myconn, adOpenDynamic, adLockOptimistic
--where "rs" is your Recordset. Hope this helps!
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)
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)
recordset.Open Source, ActiveConnection, CursorType, LockType, Options
recordset.Open "SELECT farebase.* From farebase;", myconn, adOpenDynamic, adLockOptimistic, Options
Hope this helps.