Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Issue with  MyConn VB6 to access dbase

Posted on 2010-11-28
10
Medium Priority
?
449 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
9 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 2000 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

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!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

877 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