|
-
Aug 14th, 2001, 04:31 PM
#1
Thread Starter
Member
I need help using ODBC
Below is some code that I have pieced together from help files, forums and out my backside. I have never used ODBC/DAO and therefore have no understanding of them whatsoever. When I run this code I get:
Run-time error '3027':
Can't update. Database or object is read-only.
The program is running on a windows 9x and is trying to save its data to a file on an AS/400.
What am I doing wrong, is this mess even close to right. Any comments or help would greatly be appriciated. Thanx
Option Explicit
Dim db As DAO.Database, rs As DAO.Recordset, ws As DAO.Workspace
Function AddToDatabase(SendEvent As String)
'Open the custcdt table
****************************************************
********************ERROR OCCURS HERE***************
***
Set rs = db.OpenRecordset("SELECT * FROM EPA", dbOpenDynaset)
***
********************ERROR OCCURS HERE***************
****************************************************
With rs
'Set it to Add mode
.AddNew
'Enter the field values
Select Case SendEvent
Case "EPA"
.Fields("EBLOWER").Value = lbl40538.Caption 'East Blower Damper Position
.Fields("WBLOWER").Value = lbl40537.Caption 'West Blower Damper Position
.Fields("AFCEPLN").Value = lbl40539.Caption 'A fce Plenum Damper Position
.Fields("BFCEPLN").Value = lbl40540.Caption 'B fce Plenum Damper Position
.Fields("AFCEH2O").Value = lbl40569.Caption 'A fce Water Cooled Damper Position
.Fields("BFCEH2O").Value = lbl40570.Caption 'B fce Water Cooled Damper Position
.Fields("FCEBLIN").Value = lbl40571.Caption 'fce Blower Inlet Damper Position
.Fields("FCEBLOUT").Value = lbl40572.Caption 'fce Blower Outlet Damper Position
.Fields("FCEBLCUR").Value = lbl40573.Caption 'fce Blower Current
.Fields("FCEE1000").Value = lbl40574.Caption 'fce East 1000 HP Blower Current
.Fields("FCEW1000").Value = lbl40575.Caption 'fce West 1000 HP Blower Current
.Fields("EPADATE").Value = Date 'Date of data saved.
.Fields("EPATIME").Value = Time 'Time of data saved.
Case "ChgA"
.Fields("CHGASTR").Value = lblStartA.Caption 'Start Time of Charge fce A
.Fields("CHGAEND").Value = lblEndA.Caption 'End Time of Charge fce A
.Fields("CHGASUM").Value = lblSumA.Caption 'Sum Time of Charge fce A
.Fields("EPADATE").Value = Date 'Date of data saved.
.Fields("EPATIME").Value = Time 'Time of data saved.
Case "ChgB"
.Fields("CHGBSTR").Value = lblStartB.Caption 'Start Time of Charge fce B
.Fields("CHGBEND").Value = lblEndB.Caption 'End Time of Charge fce B
.Fields("CHGBSUM").Value = lblSumB.Caption 'Sum Time of Charge fce B
.Fields("EPADATE").Value = Date 'Date of data saved.
.Fields("EPATIME").Value = Time 'Time of data saved.
End Select
'Update it
.Update
'Close it
.Close
End With
End Function
Private Sub Form_Load()
Set ws = DBEngine.CreateWorkspace("", "", "", dbUseODBC)
Set db = ws.OpenConnection("", , , "ODBC;DSN=EPA;uid=;pwd=;")
' Set db = OpenDatabase("", , , "ODBC;DSN=TestODBC;uid=;pwd=;")
End Sub
Private Sub txt40650_Change()
Call AddToDatabase("ChgA")
End Sub
Private Sub txt40655_Change()
Call AddToDatabase("ChgB")
End Sub
Josey Wales : "You a bounty hunter?"
Bounty Hunter : "A man's got to do something for a living these days."
Josey Wales : "Dying ain't much of a living, boy."
-
Aug 14th, 2001, 08:52 PM
#2
PowerPoster
For help with dao see karl moores tutorial on access db's on vb-world
Where have you set db? Post the code for it?
What is EPA? Is it a table?
Have you already opened/Set rs?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|