Hey, Guys
Please, Can you help with an DAO issue?
I need to use an Excel data base instead of an Access data base.
I am having a problem with this command: Recordset.FindFirst
I guess that the syntax is not ok.
The problem: rs.FindFirst "[FirstName] = " & Chr(34) & Resp & Chr(34)
Here is the code:
Thanks a lot!
Please, Can you help with an DAO issue?
I need to use an Excel data base instead of an Access data base.
I am having a problem with this command: Recordset.FindFirst
I guess that the syntax is not ok.
The problem: rs.FindFirst "[FirstName] = " & Chr(34) & Resp & Chr(34)
Here is the code:
Code:
Option Explicit
Private Add2 As String
Private Name2 As String
Private db As DAO.Database
Private rs As DAO.Recordset
Sub DefineNamesFiles()
Add2 = "C:\Users\vpoliveira\Desktop\"
Name2 = "base.xlsx"
End Sub
Sub EditDataBase()
Dim Resp As String
Call DefineNamesFiles
Set db = OpenDatabase(Add2 & Name2, False, False, "Excel 12.0")
Set rs = db.OpenRecordset("Plan1$")
Resp = InputBox("Inform the name")
'***************************************************
rs.FindFirst "[FirstName] = " & Chr(34) & Resp & Chr(34)
'***************************************************
'-------------------------------------------------------------------
If rs.NoMatch = True Then
MsgBox "Not Found", vbOKOnly + vbInformation, "DAO information"
Exit Sub
Else
'Edit data in recordset
rs.Edit
rs!FirstName = InputBox("Digite o novo nome")
rs!City = InputBox("Digite a nova cidade")
rs!Country = InputBox("Digite o novo nome do paÃ*s")
'Update data
rs.Update
End If
'-----------------------------------------------------------------
MsgBox "Success!"
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
End Sub
Thanks a lot!