Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21096

Inputing data into Microsoft Access from Visual Basic 6 Problem

$
0
0
Hi,
I’m completely new to Visual Basic 6, I only learned the basic a bit from a book Visual Basic for Beginner.
So when it came to a harder coding, I got easily confused.
I have a problem in inputting my data from Visual basic 6 to Microsoft Access 2010.
I did a little searching in internet and found a code.

The author of the code do these things before doing the coding,
Changing the access format to 2003 format (.mdb)
Saving the visual basic on the same folder as the Microsoft Access save file
Project > References, and activating Microsoft ActiveX Data Object 2.8 Library

This is the coding that I used :

Public kon As New ADODB.Connection
Public rs1 As New ADODB.Recordset

Private Sub Command1_Click()
Dim SQLTambah As String
SQLTambah = "insert into tb1(Name,Age,Company, Book) values ('" _
&Text1& "','" &Text2& "','" &Text3& "','" &Text4& "')"
kon.Execute SQLTambah
End Sub

Private Sub Form_Activate()
Set kon = New ADODB.Connection
Set rs1 = New ADODB.Recordset
kon.Open "provider=Microsoft.jet.oledb.4.0;data source=" & App.Path & "\Report1.mdb"
End Sub

This work just fine, it works when I Input my from Text1, Text2, Text 3, and Text4 to
Access Field on Name,Age,Company and Book.


But when I added the fifth one I only added the coding a bit into :

Public kon As New ADODB.Connection
Public rs1 As New ADODB.Recordset

Private Sub Command1_Click()
Dim SQLTambah As String
SQLTambah = "insert into tb1(Name,Age,Company,Book, Title) values ('" _
&Text1& "','" &Text2& "','" &Text3& "','" &Text4& "','" &Text5& "')"
kon.Execute SQLTambah
End Sub

Private Sub Form_Activate()
Set kon = New ADODB.Connection
Set rs1 = New ADODB.Recordset
kon.Open "provider=Microsoft.jet.oledb.4.0;data source=" & App.Path & "\Report1.mdb"
End Sub

It no longer work, I made sure that the naming of the fifth field in Microsoft Access is right which is “Title”
and the naming on my Textbox is Text5 is right as well.

It gives me Error that said :
Run-Time Error ‘-2147217900 (80040e14)’:
Syntax Error in INSERT INTO statement.

When I debug it, the program highlight the
Kon.execute SQLTambah

Can someone hep me fix this error please ? or explain what just happened ?

If there are no way around it,
Does anyone have another coding that I could use for inputing data from Visual Basic 6 to Microsoft Access 2010?
Preferably one that doesn’t include DataGrid being shown in the Visual Basic.
It’s because I don’t want to show the data in the program.
Unless The visibility of the data grid could be turned off ?

Thank you for the help before hand

Viewing all articles
Browse latest Browse all 21096

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>