我有这段代码:
Private Sub cmdAdd_Click()
Dim dbs As DAO.Database
Dim rsPhone As DAO.Recordset
If IsNull(Me.listPrzyczyna) Or Me.listPrzyczyna = "" Then
MsgBox "Wybierz przyczynę awarii!", vbOKOnly, "Wymagane dane"
Me.listPrzyczyna.SetFocus
Else
Set dbs = CurrentDb
Set rsPhone = dbs.OpenRecordset("dbZmiana")
Do While Not rsPhone.EOF
Dim strSQL As String
Dim strSQLSMSSend As String
strSQL = "INSERT INTO dbAwarieOtwarte (nrMaszyny, nazwaMaszyny, Zglaszajacy, dataZgloszenia, dataZakonczenia, godzinaZgloszenia, Przyczyna, Obszar, Telefon, Komentarz) VALUES ('" & Me!txtNrMaszyny & "', '" & Me!txtNazwa & "', '" & Me!txtZglaszajacy & "', '" & Me!txtData & "', '" & Me!txtData & "', '" & Me!txtGodzina & "', '" & Me!listPrzyczyna & "," & Me!txtNazwa & "," & Me!txtNrMaszyny & "," & Me!txtObszar & "', '" & Me!txtObszar & "', '" & Me!txtTel & "', '" & Me!txtKomentarz & "');"
strSQLSMSSend = "INSERT INTO dbSMSSend (Przyczyna, Telefon) VALUES ('" & Me!SMSSendRequest & "', '" & txtTel & "');"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.RunSQL strSQLSMSSend
DoCmd.SetWarnings True
rsPhone.MoveNext
Loop
rsPhone.Close
Set rsPhone = Nothing
dbs.Close
Set dbs = Nothing
DoCmd.Close
' DoCmd.OpenReport "repAwariaOtwarta", acViewPreview, , "ID=" & DMax("ID", "dbAwarieOtwarte")
End If
End Sub
这是dbZmiana中每个电话号码的循环,因此我为每个提供的号码分隔了strSQL插入。
一切顺利,但我碰到了一个问题。在每个循环中,我想将“循环”电话号码作为字符串插入到strSQLSMSSend中。 这个数字应该进入Telefon,我不知道如何在每个循环中引用该rs值。
现在有一个'& txtTel&''值,我如何插入rs值而不是它?
答案 0 :(得分:0)
怎么样:
strSQLSMSSend = "INSERT INTO dbSMSSend (Przyczyna, Telefon) VALUES ('" & Me!SMSSendRequest & "', '" & rsPhone!txtTel.Value & "');"