Computing.Net > Forums > Programming > VB6 and MS Access

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

VB6 and MS Access

Reply to Message Icon

Original Message
Name: jonwiper
Date: April 4, 2005 at 06:26:12 Pacific
Subject: VB6 and MS Access
OS: Windows XP
CPU/Ram: 1 Ghz 128Mb Ram
Comment:

I am trying to send and retrieve data from an MS Access Database I have created through VB6. I am using the following code which should send the data to my database where 'Players' is my table when I click on the submit button. It is however not working and I am getting an error saying 'User-defined type not defined' and the first line is highlighted. Any ideas? Please!

Dim cn As ADODB.Connection
Dim myRecordSet As ADODB.Recordset
Dim strsql As String

Set cn = New ADODB.Connection
cn.ConnectionString = Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\My Documents\Visual Work\db1.mdb;Persist Security Info=False
cn.Open

strsql = "INSERT INTO Players(field2,field3) VALUES('" & Text1 & "', '" & Text2 & "');"

Set myRecordSet = New ADODB.Recordset
myRecordSet.Open strsql, cn

Set myRecordSet = Nothing


Report Offensive Message For Removal


Response Number 1
Name: Chi Happens
Date: April 4, 2005 at 11:11:08 Pacific
Reply: (edit)

you need to add the Microsoft Active X Database resource to your project.

Click on Project/Resources and then press 'M' until you see these listed.

Click on 2.5 or higher and then click OK.

Chi

They mostly come at night...mostly


Report Offensive Follow Up For Removal

Response Number 2
Name: jon wiper
Date: April 5, 2005 at 04:14:44 Pacific
Reply: (edit)

Thanks with the new refernce it seems to work to some extent, no syntax errors now just runtime.

With the code above; I am getting the response 'Syntax error in INSERT INTO STATEMENT' when i click debug it highlights the line of code: myRecordSet.Open strsql, cn

This is very interesting as later on in my project on a different form when trying to read from the same database but a different table. I get the error message 'Data type mismatch in criteria expression' when I debug this error it points me again to the same line of code that it does have above.

This is really frustrating me as all that is wrong with my project is the database and the vb forms not interacting properly. It must be something simple surely that as a novice im just missing!? Please help, much appreciated. Jon


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge
Poll History




Data Recovery Software