Solved

Issue with  MyConn VB6 to access dbase

Posted on 2010-11-28
10
444 Views
Last Modified: 2012-05-10
Hello all,,

In my first code , everything was ok to find if the value in txtNomemploye1.Text was in my access dbase.

Set MyConn = New ADODB.Connection
    MyConn.Open "Provider=Microsoft.ACE.OLEDB.12.0;;Data Source=" & Form4.txtBaseDe.Text
    MyRecSet1.Open "SELECT * FROM [Employés] WHERE Nom='" & txtNomemploye1.Text & "'", MyConn, adOpenForwardOnly, adLockReadOnly


But now, i need to look if txtNomemploye1 and txtPrenomEmploye exist.


Set MyConn = New ADODB.Connection
    MyConn.Open "Provider=Microsoft.ACE.OLEDB.12.0;;Data Source=" & Form4.txtBaseDe.Text
    MyRecSet1.Open ("SELECT * FROM Employés WHERE" _
    & "Nom ='" & txtNomemploye1.Text & "'" _
    & "Prénom ='" & txtPrenomEmploye.Text & "'" _
    & "MyConn, adOpenForwardOnly, adLockReadOnly &")


If it exist, it will say:

 Else
        MyRecSet1.close
        MsgBox "Existe déjà dans la base de données", vbCritical, "Failure adding"
End if


Now i have a run time error 3709

Thanks for your help.

If (a = 6) Then
        ' il a cliqué sur OUI
    'Insert data in Microsoft Access Data Base
    Dim MyConn As ADODB.Connection
    Dim MyRecSet1 As New ADODB.Recordset
    

    Set MyConn = New ADODB.Connection
    MyConn.Open "Provider=Microsoft.ACE.OLEDB.12.0;;Data Source=" & Form4.txtBaseDe.Text
    MyRecSet1.Open ("SELECT * FROM Employés WHERE" _
    & "Nom ='" & txtNomemploye1.Text & "'" _
    & "Prénom ='" & txtPrenomEmploye.Text & "'" _
    & "MyConn, adOpenForwardOnly, adLockReadOnly &")


    If MyRecSet1.EOF Then
        MyRecSet1.close
        Set MyRecSet1 = MyConn.Execute( _
          "INSERT INTO [Employés]  (Nom, Prénom, Adresse, Ville, Code_postal, Numéro_de_Téléphone, Cellulaire, Courriel, Jour, Mois, Année, Numéro_assurance_social) VALUES ( '" & _
          txtNomemploye1.Text & _
          "' , '" & txtPrenomEmploye.Text & "' ,  '" & txtAdresse.Text & "' ,'" & txtVille.Text & "' ,'" & txtCodePostal.Text & "' ,'" & txtNumeroDe.Text & "' , '" & txtCellulaire.Text & _
          "' , '" & txtCourriel.Text & "' , '" & ComJour.Text & "' , '" & ComMois.Text & "' ,'" & ComAnnée.Text & _
          "' , '" & txtAssuranceSocial.Text & "' )")
        MsgBox "Nouvelle employé enregistré"  ', vbCritical, "Succesful adding"
    Else
        MyRecSet1.close
        MsgBox "Existe déjà dans la base de données", vbCritical, "Failure adding"
    End If

    MyConn.close

Open in new window

0
Comment
Question by:Wilder1626
  • 6
  • 3
10 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 34226275
perhaps adding the AND statement would help here
syntax of multiple checks is like this

WHERE ...
AND ...

there is also

OR


Set MyConn = New ADODB.Connection
    MyConn.Open "Provider=Microsoft.ACE.OLEDB.12.0;;Data Source=" & Form4.txtBaseDe.Text
    MyRecSet1.Open ("SELECT * FROM Employés WHERE" _
    & "Nom ='" & txtNomemploye1.Text & "'  AND " _
    & "Prénom ='" & txtPrenomEmploye.Text & "'" _
    & "MyConn, adOpenForwardOnly, adLockReadOnly &")
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 34226286
Hello rockiroads,

I tried this:

Set MyConn = New ADODB.Connection
    MyConn.Open "Provider=Microsoft.ACE.OLEDB.12.0;;Data Source=" & Form4.txtBaseDe.Text
    MyRecSet1.Open ("SELECT * FROM Employés WHERE" _
    & "Nom ='" & txtNomemploye1.Text & "' AND " _
    & "Prénom ='" & txtPrenomEmploye.Text & "'" _
    & "MyConn, adOpenForwardOnly, adLockReadOnly &")

But still the same error.
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 34226307
oh, I just noticed MyConn on the end of your string. You are appending MyConnn rather than adding as an argument. Looks like copy/paste error
as well as no space after the WHERE

good practice is to define your sql in a string then use that. you will find it easier to debug
eg


Dim sSql As String

Set MyConn = New ADODB.Connection

    MyConn.Open "Provider=Microsoft.ACE.OLEDB.12.0;;Data Source=" & Form4.txtBaseDe.Text

    sSql = "SELECT * FROM Employés WHERE " _
            & "Nom ='" & txtNomemploye1.Text & "' AND " _
            & "Prénom ='" & txtPrenomEmploye.Text & "'"

    MyRecSet1.Open sSql, MyConn, adOpenForwardOnly, adLockReadOnly
    On Error GoTo cmdExportToExcel_Click_Error
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Author Comment

by:Wilder1626
ID: 34226321
Just this and now it work

Dim sSql As String

Set MyConn = New ADODB.Connection

    MyConn.Open "Provider=Microsoft.ACE.OLEDB.12.0;;Data Source=" & Form4.txtBaseDe.Text

    sSql = "SELECT * FROM Employés WHERE " _
            & "Nom ='" & txtNomemploye1.Text & "' AND " _
            & "Prénom ='" & txtPrenomEmploye.Text & "'"

    MyRecSet1.Open sSql, MyConn, adOpenForwardOnly, adLockReadOnly
 

I just gona some test
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 34226443
Hello all

This topic was closed by mistake.

Can you please re open?

Thanks
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 34226444
Hello all

This topic was closed by mistake.

Can you please re open?

Thanks
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 34226454
Something is wrong here,

I accept and it closed the topic
0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 34226644
Is it working now?
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 34226709
lol vee_mod
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question