Vba

Résolu
sofien86 Messages postés 19 Date d'inscription jeudi 28 août 2008 Statut Membre Dernière intervention 15 janvier 2009 - 29 août 2008 à 14:58
sofien86 Messages postés 19 Date d'inscription jeudi 28 août 2008 Statut Membre Dernière intervention 15 janvier 2009 - 2 sept. 2008 à 10:45
je vien de comencé a etulise visuel basic et j sui en trei de devlope un tableau dans sql qui comandes par une variable en vijeo look j creé un bouton pour enregistré la niveau et la date je suis enfeni arive Private Sub Group1_Click()
Dim mess
Dim today As String
today = Now
Dim str, objConnection, objCommand, oRs, strSQL
Dim niveau As Variable
Set niveau = Variables.Add("Device1.Niveau")

str = "provider=msdasql; Initial Catalog= mohamed ; DSN=mohamed"

strSQL = "INSERT INTO niveau VALUES( 'today' ,'niveau' )"
Set objConnection = CreateObject("ADODB.Connection")

objConnection.ConnectionString = str
objConnection.CursorLocation = 3
objConnection.Open

If Err.Number <> 0 Then
mess = MsgBox("Pas de connexion", 0, "Erreur")
Err.Clear

End If


Set oRs = CreateObject("ADODB.Recordset")
Set objCommand = CreateObject("ADODB.Command")
objCommand.CommandType = 1
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = strSQL
Set oRs = objCommand.Execute


If Err.Number <> 0 Then
mess = MsgBox("Erreur d'execution: 02", 0, "Erreur")
Err.Clear

End If


Set objCommand = Nothing
objConnection.Close
Set objConnection = Nothing
End Sub


est ce que quel q'un peut me aide merci d'avence

10 réponses

cs_Exploreur Messages postés 4821 Date d'inscription lundi 11 novembre 2002 Statut Membre Dernière intervention 15 novembre 2016 15
29 août 2008 à 15:07
Salut,

Déjà recommence ta question plus proprement pour que l'on puisse mieux comprendre ton problème...car la mise en page n'est pas vraiment super chouette ^^

A+
Exploreur

 Linux a un noyau, Windows un pépin
3
jrivet Messages postés 7392 Date d'inscription mercredi 23 avril 2003 Statut Membre Dernière intervention 6 avril 2012 60
1 sept. 2008 à 10:27
Salut,
Si tu cherches à insérer dans ta table Niveau , le Niveau et la Date à un instant T j'essaierai pêu etre

=> Si cela ne convient pas, donne nous peut être TOUTES les colonnes de la table Niveau car il est possible qu'il faille les renseigner lors de l'ajout.

Private Sub Group1_Click()
   Dim today As String
   Dim str As String
   Dim strSQL As String
   Dim niveau As Variable
   Dim objConnection, objCommand,
   
   today = Now
   Set niveau = Variables.Add("Device1.Niveau")
   str = "provider=msdasql; Initial Catalog= mohamed ; DSN=mohamed"
   Set objConnection = CreateObject("ADODB.Connection")
   objConnection.ConnectionString = str
   objConnection.CursorLocation = 3
   objConnection.Open
   If Err.Number <> 0 Then
       mess = MsgBox("Pas de connexion", 0, "Erreur")
       Err.Clear
   End If
   
   strSQL = "INSERT INTO niveau (Today, Niveau) VALUES(" & today & " ,'" & niveau & "' )"
   'Ou alors strSQL = "INSERT INTO niveau (Today, Niveau) VALUES('" & Today & "' ,'" & niveau & "' )"
   Set objCommand = CreateObject("ADODB.Command")
   objCommand.CommandType = 1
   Set objCommand.ActiveConnection = objConnection
   objCommand.CommandText = strSQL
   Call objCommand.Execute
   If Err.Number <> 0 Then
       mess = MsgBox("Erreur d'execution: 02", 0, "Erreur")
       Err.Clear
   End If
   Set objCommand = Nothing
   objConnection.Close
   Set objConnection = Nothing
End Sub , ----
[code.aspx?ID=41455 By Renfield]

@+: Ju£i€n
Pensez: Réponse acceptée
3
jrivet Messages postés 7392 Date d'inscription mercredi 23 avril 2003 Statut Membre Dernière intervention 6 avril 2012 60
1 sept. 2008 à 10:28
Re,
Oups une petite erreur s'est glissée dans la ligne

 Dim objConnection, objCommand,

deviendra

 Dim objConnection, objCommand 'et oui pas besoin de virgule

@+: Ju£i€n
Pensez: Réponse acceptée
3
sofien86 Messages postés 19 Date d'inscription jeudi 28 août 2008 Statut Membre Dernière intervention 15 janvier 2009
2 sept. 2008 à 10:18
merci jrivet
3

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
sofien86 Messages postés 19 Date d'inscription jeudi 28 août 2008 Statut Membre Dernière intervention 15 janvier 2009
2 sept. 2008 à 10:21
mon nouveau problem c a chaque fois que je cherche une date il faut que je retourne et alez jusque le serveur pour voitr la table dans SQL je veux creé une bonde (date de debu de recherche, date du fin de recherche ) et a chaque fois que je fai entre les date il me indique tout les enregistrement de ce intervale dans le SQL je sui debuton, Si quelqun peut me aide je c pas si je cree un table dans le vba ou je f quoi exactement ??? Merci
3
jrivet Messages postés 7392 Date d'inscription mercredi 23 avril 2003 Statut Membre Dernière intervention 6 avril 2012 60
2 sept. 2008 à 10:27
Salut,
Regarde comment faire une requete SELECT

Aide

SELECT * FROM Niveau WHERE today BETWEEN DateDeb AND DateFin

=> il faudra mettre DateDeb Et DateFIn comme je te montrait pour inserer la valeur de ta varaible Today

@+: Ju£i€n
Pensez: Réponse acceptée
3
jrivet Messages postés 7392 Date d'inscription mercredi 23 avril 2003 Statut Membre Dernière intervention 6 avril 2012 60
2 sept. 2008 à 10:38
Salut,
Je te mets sur la piste, a toi de chercher sur le Web.

@+: Ju£i€n
Pensez: Réponse acceptée
3
sofien86 Messages postés 19 Date d'inscription jeudi 28 août 2008 Statut Membre Dernière intervention 15 janvier 2009
2 sept. 2008 à 09:58
j déjà trouver la solution et voila la solution si quel q’ un peut ce servie un jour merci pour vous de m'avoir aider plus précisément dans le logicielle Vijeo look c un logicielles de super vision j’ai voulu criée un bouton dan le quelle a chaque fois que je click a ce bouton il enregistre la niveau et la date a une instant t en utilisent le SQL comme une base c tou alor j trouvé en fin la solution suivante Private Sub Group1_Click()
Dim mess
Dim today As String
today = Now
Dim str, objConnection, objCommand, oRs, strSQL
Dim niveau As Variable
Set niveau = Variables.Add("Device1.Niveau")

str = "provider=msdasql; Initial Catalog= mohamed ; DSN=mohamed"

strSQL = "INSERT INTO niveau VALUES( '" & today & "' ,'" & niveau & "' )"
Set objConnection = CreateObject("ADODB.Connection")

objConnection.ConnectionString = str
objConnection.CursorLocation = 3
objConnection.Open

If Err.Number <> 0 Then
mess = MsgBox("Pas de connexion", 0, "Erreur")
Err.Clear

End If


Set oRs = CreateObject("ADODB.Recordset")
Set objCommand = CreateObject("ADODB.Command")
objCommand.CommandType = 1
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = strSQL
Set oRs = objCommand.Execute


If Err.Number <> 0 Then
mess = MsgBox("Erreur d'execution: 02", 0, "Erreur")
Err.Clear

End If


Set objCommand = Nothing
objConnection.Close
Set objConnection = Nothing
End Sub
0
sofien86 Messages postés 19 Date d'inscription jeudi 28 août 2008 Statut Membre Dernière intervention 15 janvier 2009
2 sept. 2008 à 10:34
merci pour votre reponse mes si tu peut me envoiyer un exemple par ce que je sui debuton merci infiniment
0
sofien86 Messages postés 19 Date d'inscription jeudi 28 août 2008 Statut Membre Dernière intervention 15 janvier 2009
2 sept. 2008 à 10:45
ok merci
0
Rejoignez-nous