I put together an Access form that links to a simple table called faxination1. I was able to get the strSQL to run but the user has to hit the cmdSearch button for each record on the table. I am trying to get a recordset connected to the table so that I can set a loop to work until it reaches the end of the recordset. However, I get a compile error that says invalid use of New keyword and I can't figure out where I went wrong. I tried changing the Set rstFax = New Recordset to ... = New ADODB.Recordset but that causes lots of other problems. We have another DB that uses the same New keyword the same way I'm using it and it works fine. Here is my code:
Private Sub cmdSearch_Click()
Dim conDB As ADODB.Connection
Dim rstFax As ADODB.Recordset
Dim strSQL As String
Set conDB = CurrentProject.Connection
strSQL = "UPDATE [AM Completions] INNER JOIN Faxination1 ON [AM Completions].PHONE = Faxination1.Phone SET Faxination1.[Prov Type] = [am completions].[prov type], Faxination1.[Order Id] = [am completions].[order id] WHERE ((([AM Completions].PHONE)= " & Phone & "));"
Set rstFax = New Recordset
rstFax.CursorLocation = adUseClient
rstFax.Open strSQL, conDB, adOpenDynamic, adLockOptimistic
If rstFax.RecordCount > 0 Then
Do While Not rstFax.EOF
DoCmd.RunSQL strSQL
Me.Requery
Loop
Else
Exit Sub
End If
End Sub
Private Sub cmdSearch_Click()
Dim conDB As ADODB.Connection
Dim rstFax As ADODB.Recordset
Dim strSQL As String
Set conDB = CurrentProject.Connection
strSQL = "UPDATE [AM Completions] INNER JOIN Faxination1 ON [AM Completions].PHONE = Faxination1.Phone SET Faxination1.[Prov Type] = [am completions].[prov type], Faxination1.[Order Id] = [am completions].[order id] WHERE ((([AM Completions].PHONE)= " & Phone & "));"
Set rstFax = New Recordset
rstFax.CursorLocation = adUseClient
rstFax.Open strSQL, conDB, adOpenDynamic, adLockOptimistic
If rstFax.RecordCount > 0 Then
Do While Not rstFax.EOF
DoCmd.RunSQL strSQL
Me.Requery
Loop
Else
Exit Sub
End If
End Sub