Problem with VBA 6.0 and MySQL
Hello,
I've a problem and I'm really getting stuck.
I use the following VBcode
Code:
Dim DbPath As String
Dim Slash As String
DbPath = "DRIVER={MySQL ODBC 5.1 Driver};" _
& "SERVER=localhost;" _
& "DATABASE=wozoco;" _
& "UID=root;" _
& "PWD=;" _
& "OPTION=3"
Dim Db As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Db.Open DbPath
Rs.ActiveConnection = Db
Rs.CursorType = adOpenKeyset
Rs.LockType = adLockOptimistic
Rs.Source = "dom" 'Naam Tabel
Rs.Open
Rs.AddNew
Rs!actie = "test"
Rs.Update
Rs.Close
Set Rs = Nothing
Db.Close
Set Db = Nothing
The data is saved in the following database.
Code:
CREATE TABLE `dom` (
`id` int(10) NOT NULL,
`actie` longtext NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
I get the following error:
Code:
Run-time error '-2147467259 (80004005)'
[MySQL][ODBC 5.1 Driver][mysqld-5.1.30-community-log]
Column actie cannot be null
What's going wrong and how can I fixed it?
Thanks in advance for your reply.
PH-MJS
Re: Problem with VBA 6.0 and MySQL
You created it as NOT NULL - that means it can not be empty. You would fix your problem by passing it data when you add a record.
In addition, id is set as NOT NULL which means that it also MUST have an entry for all new records.
Re: Problem with VBA 6.0 and MySQL
Hello Hack,
Thanks for your reply.
As shown in the code, I try to add "test" in the database in field "actie"
So, the data is not Null or empty. Maybe is it an other cause.
Thanks in advance for your reply.
PH-MJS
Re: Problem with VBA 6.0 and MySQL
The error message appears to have mentioned the wrong field - as Hack said, based on the table definition you need to set values for both of the fields (if "ID" was an Identity/AutoNumber you could leave it Null, and let the database create the value).