Voici une excellente façon de convertir une chaîne SQL en code VBA.
Création du formulaire
Le formulaire a juste besoin de deux zones de texte et un bouton de commande. Les instructions SQL peuvent être assez longues, vous devez donc placer les zones de texte sur différentes pages d'un contrôle onglet.
Create a new form (in design view.)
Add a tab control.
In the first page of the tab control, add a unbound text box.
Set its Name property to txtSql.
Increase its Height and Width so you can see many long lines at once.
In the second page of the tab control, add another unbound text box.
Name it txtVBA, and increase its height and width.
Above the tab control, add a command button.
Name it cmdSql2Vba.
Set its On Click property to [Event Procedure].
Click the Build button (...) beside this property.
When Access opens the code window, set up the code like this:
Private Sub cmdSql2Vba_Click()
Dim strSql As String
'Purpose: Convert a SQL statement into a string to paste into VBA code.
Const strcLineEnd = " "" & vbCrLf & _" & vbCrLf & """"
If IsNull(Me.txtSQL) Then
Beep
Else
strSql = Me.txtSQL
strSql = Replace(strSql, """", """""") 'Double up any quotes.
strSql = Replace(strSql, vbCrLf, strcLineEnd)
strSql = "strSql = """ & strSql & """"
Me.txtVBA = strSql
Me.txtVBA.SetFocus
RunCommand acCmdCopy
End If
End Sub
http://allenbrowne.com/ser-71.html
Bienvenue sur Stack Overflow! S'il vous plaît lire [* Pourquoi est-ce que quelqu'un peut m'aider? "Pas une question réelle? *] (Https://meta.stackoverflow.com/q/284236/1188513) - puis relisez votre message et [modifier] de sorte que il comprend une question claire. –