PDA

Click to See Complete Forum and Search --> : Databases


Dec 1st, 1999, 06:05 PM
Any body fancy havin a go at debugging this for me?
It's the code that the Dataform Wizard spewed out, but I'm trying to modify it to run in a module with out loading a seperate form (it's part of a cgi program so I need to keep is as small & memory friendly as poss...)

When I run it, VB doesn't like the the dim withevents... bit, the Set db = New Connection and much more. I've been fiddling with it for ages and I'm getting really fustrated. Help!!

Private Sub Write_To_Database()

Dim withevents adoPrimaryRS As Recordset
Dim mbEditFlag As Boolean
Dim mbAddNewFlag As Boolean
Dim mbDataChanged As Boolean


' ==Please don't Crash!!!=======

On Error Resume Next

'======== Load Database ==============

Dim db As Connection
Set db = New Connection
db.CursorLocation = adUseClient
db.Open "PROVIDER=Microsoft.Jet.OLEDB.3.51;Data Source=c:\mcg.mdb;"

Set adoPrimaryRS = New Recordset
adoPrimaryRS.Open "select Availability,Catagory,Email,Enquiry,Host,[IP Address],Name,News,Telephone,User from Ste", db, adOpenStatic, adLockOptimistic

'======== Create Text & Check Boxes =====
Dim txtAvailability As TextBox
Dim txtCatagory As TextBox
Dim txtEmail As TextBox
Dim txtEnquiry As TextBox
Dim txtHost As TextBox
Dim txtIPAddress As TextBox
Dim txtName As TextBox
Dim txtTelephone As TextBox
Dim txtUser As TextBox
Dim chkNews As CheckBox

'=======Bind Text & Checkboxes to Database ========

txtAvailability.DataSource = adoPrimaryRS
txtCatagory.DataSource = adoPrimaryRS
txtEmail.DataSource = adoPrimaryRS
txtEnquiry.DataSource = adoPrimaryRS
txtHost.DataSource = adoPrimaryRS
txtIPAddress.DataSource = adoPrimaryRS
txtName.DataSource = adoPrimaryRS
txtTelephone.DataSource = adoPrimaryRS
txtUser.DataSource = adoPrimaryRS
chkNews.DataSource = adoPrimaryRS

mbDataChanged = False

'=======Update Fields==================

txtAvailability = sContactTime
txtCatagory = sCatagory
txtEmail = sEMail
txtEnquiry = sEnquiry
txtHost = CGI_RemoteHost
txtIPAddress = CGI_RemoteAddr
txtName = sName
txtTelephone = sTelephone
txtUser = txtUser
If UCase$(sNews) = "ON" Then
chkNews = True
Else
chkNews = False
End If

'=======Update Database==============

adoPrimaryRS.UpdateBatch adAffectAll

If mbAddNewFlag Then
adoPrimaryRS.MoveLast 'move to the new record
End If

mbEditFlag = False
mbAddNewFlag = False
mbDataChanged = False

End Sub

I did post this in the Database Q&A section, but I didn't get any replies...so now it's here too!

Andy Collyer
Dec 1st, 1999, 06:30 PM
Is the control included in your components?

AndyC

Dec 1st, 1999, 07:19 PM
Don't think it needs to be because I'm not actually using it on a form: just dynamically creating in in a module at runtime...

I just tried putting in in anyway and it still encounters the same problems.

Incidentally, the Data Form wizard didn't include it as a component either.

------------------
Matthew Ralston
E-Mail: m.ralston@mediavault.co.uk
ICQ:31422892 (http://www.thebluelink.cjb.net/icq.html)
Web Sites:The Blue Link (http://www.thebluelink.cjb.net) My Home Page (http://mralston.cjb.net)

gpiper
Dec 2nd, 1999, 08:36 AM
My guess is that you don't have the proper references. Andy Collyer had the right idea. When you add the control to your form, it automatically adds the proper Database references. You can also manually add the references. Click Project, then References in the pull-down menu in VB. I think the one you need is the Microsoft DAO 3.5 Object Library.

I hope this helps.

Glenn

LG
Dec 2nd, 1999, 10:55 AM
Hi,Matthew.
WithEvent is a reserved VB word for creating custom events. From your code it doesn't look that is what you wanted to do. Am I wrong?
Larisa