Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open access database table In VB6

Status
Not open for further replies.

goobil

Technical User
Aug 9, 2003
38
0
0
AG
Hi all,
I am not sure if I am doing it right, but I am trying to insert net data in a access database using VB6 I can connect to the database My question is how do I open the table to insert new record?
If u used the select statement that work fine.

Please help
My code below

Private Sub cmdsave_Click()
Dim oConn As New ADODB.Connection
Dim strSQL As String
Dim rsdb As ADODB.Recordset
Dim firstname As String

Set oConn = CreateObject("ADODB.Connection")
Set rsdb = CreateObject("ADODB.RecordSet")

oConn.Mode = adModeShareExclusive
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\Hfc\holyfamily.mdb;"

'Set strSQL = Open("personalinfo")
'Set rsdb = DB.OpenRecordset("personalinfo", dbOpenDynaset)
'strSQL = "Select * from personalinfo"
rsdb.Open strSQL, oConn, adOpenStatic

rsdb.AddNew
'rs("entrydate") = entrydate

'rsdb("registration") = Me![txtreg]
rsdb("fname") = Me![txtfirst]
rsdb("mname") = Me![txtmiddle]

rsdb.Update
rsdb.Close






End Sub
 
You could use the INSERT INTO statement with your connection object:


oConn.Mode = adModeShareExclusive
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\Hfc\holyfamily.mdb;"

oConn.Execute "INSERT INTO personalinfo (fname, mname)
VALUES ('" & txtfirst.Text & "','" & txtmiddle.Text & "')"

Swi
 
Hi Swi,
Thanks allot.

But i am having one more problem it's dont seem to like the value txtfirst.text.

Hi all,

I am new to VB6 trying to understand it. I’m trying to declare a variable and I am getting an error on “ xfname = txtfirst.txt “. Method or data member not found (Error 461).
The only options I have is
Xfname.count
Xfname.item
Xfname.LBound
Xfname.UBound.

Why it’s I get an error on xfname.text?

Below is me code.

Thanks in advance.


Private Sub cmdsave_Click()
Dim oConn As New ADODB.Connection
Dim strSQL As String
Dim rsdb As New ADODB.Recordset
Dim firstname, xfname As String
Dim rsd As Database



Set oConn = CreateObject("ADODB.Connection")
Set rsdb = CreateObject("ADODB.RecordSet")
'Set rsd = CreateObject("Database")

oConn.Mode = adModeShareExclusive
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\Hfc\holyfamily.mdb;"
xfname = txtfirst

oConn.Execute "INSERT INTO personalinfo (fname, mname)VALUES('”& txtfirst &”','” & txtmiddle &”')"
 
It looks as if Xfname has been coverted into an array and you will need to reference the array index:

Xfname(0)

You'll need to find out how it came to be an array, and whether that's what you intend.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Hi Johnwm,


No it not an arry it's a single text box

I have three VB book and none of then refer to this problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top