S
Stewart
I'm trying to convert(format) this sql from my query to a form I can use in
vba(or vb) and escape the DoCmd.OpenQuery "qryQuery" trap.
My query sql view:
INSERT INTO tblMessQ ( RecipID, ConCode, Message, [Date], [Ack/success] )
SELECT tblMessLog.RecipID, tblRecipients.Concode,
Forms!frmTestMess!txtTextMess AS Message, Now() AS [Date], 0 AS Ack
FROM tblMessLog INNER JOIN tblRecipients ON tblMessLog.RecipID =
tblRecipients.ID;
VBRSgen converts it to: 'was worth a shot...
Dim daoDB As DAO.Database
Dim strSQL As String
strSQL = "INSERT INTO "
strSQL = strSQL & "tblMessQ "
strSQL = strSQL & "("
strSQL = strSQL & "RecipID, "
strSQL = strSQL & "ConCode, "
strSQL = strSQL & "Message, "
strSQL = strSQL & "[Date], "
strSQL = strSQL & "[Ack/success]"
strSQL = strSQL & ") "
strSQL = strSQL & "("
strSQL = strSQL & "SELECT "
strSQL = strSQL & "INNER JOIN tblMessLog ON tblRecipients.ID =
tblMessLog.RecipID"
strSQL = strSQL & ""
strSQL = strSQL & ")"
Set daoDB = Workspaces(0).OpenDatabase("C:\Test_1.mdb")
MsgBox strSQL
daoDB.Execute (strSQL)
If Not (daoDB Is Nothing) Then
Set daoDB = Nothing
End If
** But has INSERT INTO error I can't find.
I also had no success with:
strSQL1 = "INSERT INTO tblMessQ ([RecipID], [ConCode], [Message], [Date],
[Ack/success])"
strSQL2 = "SELECT [tblMessLog].[RecipID], [tblRecipients].[Concode],
Forms!frmTestMess!txtTextMess AS Message, Now() AS [Date], 0 AS [Ack]"
strSQL3 = "FROM tblRecipients INNER JOIN tblRecipients.[ID] = '" &
[tblMessLog].[RecipID] & "' ; "
strSQL = strSQL1 & Chr(13) & strSQL2 & Chr(13) & strSQL3
MsgBox strSQL, , "SQL Contents here"
** Although it was nicely on three lines looking excatly like my original
query's sql view.
Any assistance appreciated.
vba(or vb) and escape the DoCmd.OpenQuery "qryQuery" trap.
My query sql view:
INSERT INTO tblMessQ ( RecipID, ConCode, Message, [Date], [Ack/success] )
SELECT tblMessLog.RecipID, tblRecipients.Concode,
Forms!frmTestMess!txtTextMess AS Message, Now() AS [Date], 0 AS Ack
FROM tblMessLog INNER JOIN tblRecipients ON tblMessLog.RecipID =
tblRecipients.ID;
VBRSgen converts it to: 'was worth a shot...
Dim daoDB As DAO.Database
Dim strSQL As String
strSQL = "INSERT INTO "
strSQL = strSQL & "tblMessQ "
strSQL = strSQL & "("
strSQL = strSQL & "RecipID, "
strSQL = strSQL & "ConCode, "
strSQL = strSQL & "Message, "
strSQL = strSQL & "[Date], "
strSQL = strSQL & "[Ack/success]"
strSQL = strSQL & ") "
strSQL = strSQL & "("
strSQL = strSQL & "SELECT "
strSQL = strSQL & "INNER JOIN tblMessLog ON tblRecipients.ID =
tblMessLog.RecipID"
strSQL = strSQL & ""
strSQL = strSQL & ")"
Set daoDB = Workspaces(0).OpenDatabase("C:\Test_1.mdb")
MsgBox strSQL
daoDB.Execute (strSQL)
If Not (daoDB Is Nothing) Then
Set daoDB = Nothing
End If
** But has INSERT INTO error I can't find.
I also had no success with:
strSQL1 = "INSERT INTO tblMessQ ([RecipID], [ConCode], [Message], [Date],
[Ack/success])"
strSQL2 = "SELECT [tblMessLog].[RecipID], [tblRecipients].[Concode],
Forms!frmTestMess!txtTextMess AS Message, Now() AS [Date], 0 AS [Ack]"
strSQL3 = "FROM tblRecipients INNER JOIN tblRecipients.[ID] = '" &
[tblMessLog].[RecipID] & "' ; "
strSQL = strSQL1 & Chr(13) & strSQL2 & Chr(13) & strSQL3
MsgBox strSQL, , "SQL Contents here"
** Although it was nicely on three lines looking excatly like my original
query's sql view.
Any assistance appreciated.