Hello all!
I have been Googling for a week now trying to figure out why my code won't work in this form. It seems like a simple task (don't judge by the length of this post, it really does seem like it should be simple). I'm not a savvy database guy but can work through any logic, it's usually the semantics that I get caught up on and I think that's the case now...
Details of database:
- Two tables exist (SOX and PAYMENT).
- Although the PK's from each table use different unique identifiers, there can be records from each that correspond to the other. For instance, a PAYMENT record of 2016-01 may be the same thing as SOX record 1.2016.01.
- 1 form that I use to search for a PAYMENT number and it populates a number of text boxes based on fields from the PAYMENT table.
- In the form, there is a text box that will have the SOX number (txt_PaymentSupportingReferenceID) that matches the PAYMENT record (if there is one)
What I'm trying to do:
If I look up a record and it has a SOX number, I want to click a button to populate other text boxes. For instance, another field in the form is txt_PrestoRefControlReferenceID which would be blank until I hit a View Details button, which would then populate that field from the SOX table based on the number in the txt_PaymentSupportingReferenceID text box. Hope that makes sense.
Problem with my code:
My code is pasted below. When I hit the button, all it does is paste the text in the Task line (i.e. the query itself is pasted when I click the button). I understand the logic of why it does that, but I'm trying to get it to put the RESULT of the SQL statement in the txt_PaymentRefControlReferenceID textbox. What am I missing?
Code:
Private Sub cmd_PaymentOpenSupportingID_Click()
Dim SOXRecord As String
Dim Task As String
SOXRecord = txt_PaymentSupportingReferenceID.Value
Task = "SELECT [Control Reference ID] FROM tbl_SOXDeficiencies WHERE ((Reference_ID Like ""*" & SOXRecord & "*""))"
Me.txt_PaymentRefControlReferenceID = Task
End Sub
An alternative I was going to do based on my Google results was just have a button that opens a new form that would populate all of the fields from the SOX table. I found the code below but I get some weird error that says no specific message. I'd rather do the above method but can do this if it makes it easier to get this done; I'm sick of working on this little problem.
Code:
DoCmd.OpenForm "frm_Add_Update_SOX_Deficiencies", , , "Reference_ID=" & Me!txt_PaymentSupportingReferenceID.Value
Thanks all, I appreciate any help you can give me!