Reputation: 21
At the moment, it takes an image I add to my signature folder and puts it straight into the attachments field of my contract. HOWEVER! It does not put it into the specific record for which the button is pressed- it puts the image into the signature box of the first record every time. I am new to SQL, how would I go about making it
So below is my code:
Private Sub Command21_Click()
Dim db As DAO.Database
Dim rs1 As DAO.Recordset
Dim rs2 As DAO.Recordset2
Dim strFile As String
Set db = CurrentDb()
strFile = "C:\Users\Reception\Desktop\Files\Signature\sign.png"
Set rs1 = db.OpenRecordset("Table1")
rs1.Edit
Set rs2 = rs1!GuestRegistration.Value
With rs2
.AddNew
!FileData.LoadFromFile strFile
.Update
End With
rs1.Update
Form.Refresh
Set rs2 = Nothing
Set rs1 = Nothing
Set db = Nothing
End Sub
Any help is greatly appreciated!!! Sorry I am so novice.
I tried a few things but I don't understand enough about coding to know what I was doing. I am still a beginner doing this for my business. I just need it to pt the image in the correct record rather than instantly putting it in the first record of the recordset.
Upvotes: 1
Views: 61
Reputation: 21
Nevermind!! Thank you so much @June7 for the response! I set his response code as a string and referenced it instead of Table1 so it isolates only the record I wanted. Find attached my code below if you need this for help with any projects :)
Private Sub Command21_Click()
Dim db As DAO.Database
Dim rs1 As DAO.Recordset
Dim rs2 As DAO.Recordset2
Dim strFile As String
Dim strSQL As String
strSQL = "SELECT * FROM Table1 WHERE ID=" & Me!ID
Set db = CurrentDb()
strFile = "C:\Users\Reception\Desktop\Files\Signature\sign.png"
Set rs1 = db.OpenRecordset(strSQL)
rs1.Edit
Set rs2 = rs1!GuestRegistration.Value
With rs2
.AddNew
!FileData.LoadFromFile strFile
.Update
End With
rs1.Update
Form.Refresh
Set rs2 = Nothing
Set rs1 = Nothing
Set db = Nothing
End Sub
Upvotes: 1