Results 1 to 4 of 4

Thread: Problem with VBA 6.0 and MySQL

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    2

    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

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    2

    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

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width