Question

Locked

hello experts......

By shreyaas ·
i hav little idea about VB....and i hav to do a project on that....i know c and c++
iam trying to make a connection from VB 6.0 to MS access database...........
i hav created a form which has a
first name,city,country
add,delete, save and update commands in my form.
here are my questions
1.firstly for conection should i create a data base in access ????

when i try to run the form using the run command on the tool bar, i get an error as "compile error.user defined type not defined"
for the lines "Dim adc As New ADODB.Connection"

here is the complete code.please help in making successful connection


Dim adc As New ADODB.Connection
Dim rs As New ADODB.Recordset

Private Sub cmdAdd_Click()
rs.AddNew
txtFirstName.Text = ""
txtCountry.Text = ""
txtCity.Text = ""
cmdDelete.Enabled = False
cmdAdd.Visible = False
cmdSave.Visible = True
cmdUpdate.Enabled = False
End Sub

Private Sub cmdDelete_Click()
Dim ans As String, str As String
ans = MsgBox("Do you really want to delete the current record?", vbExclamation + vbYesNo, "DELETE")
If ans = vbYes Then
adc.Execute ("delete from emp where e_name=" & txtFirstName.Text)
MsgBox ("The record has been deleted successfully.")
Set rs = Nothing
str = "select * from emp"
rs.Open str, adc, adOpenDynamic, adLockPessimistic

txtFirstName.Text = rs(0)
txtCountry.Text = rs(1)
txtCity.Text = rs(2)
End If
End Sub

Private Sub cmdSave_Click()
rs(0) = txtFirstName.Text
rs(1) = txtCounrty.Text
rs(2) = txtCity.Text
rs.Update
MsgBox "The record has been saved successfully.", , "ADD"
cmdDelete.Enabled = True
cmdSave.Visible = False
cmdAdd.Visible = True
cmdUpdate.Enabled = True
End Sub

Private Sub cmdUpdate_Click()
Dim ans As String
ans = MsgBox("Do you really want to modify the current record?", vbExclamation + vbYesNo, "DELETE")
If ans = vbYes Then
rs.Update

cmdDelete.Enabled = False
cmdUpdate.Enabled = False
cmdSave.Visible = True
cmdAdd.Visible = False
End If
End Sub

Private Sub Form_Load()
Dim str As String
Me.Caption = " Database of company"
Set adc = Nothing
adc.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\employee2.mdb;Persist Security Info=False"
str = "select * from emp"
rs.Open str, adc, adOpenDynamic, adLockPessimistic
txtFirstName.Text = rs(0)
txtCountry.Text = rs(1)
txtCity.Text = rs(2)
End Sub

This conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

Did you actually add the reference?

by Slayer_ In reply to hello experts......

Did you actually add the reference?

If you don't want to do that, or late bind it. Then change your declare statements.

Dim adc as object
dim rs as object

set adc = createobject("ADODB.Connection")
set rs = createobject("ADODB.Recordset")

Back to Web Development Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums