Solved

Issue with  MyConn VB6 to access dbase

Posted on 2010-11-28
10
441 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now