Trouble Referencing Record Based on Form

Lingster

New member
Local time
Today, 03:25
Joined
Oct 27, 2015
Messages
2
Hello All,

New here and with no programming experience. Hopefully I have the right forum. I work in medical research and need to develop an access form where radiologists can pull up a form with patient information, click a control button to start a timer, input data on the same form while the timer is going and then click a button to stop the timer. The time taken to do that procedure would then need to be logged and associated with the data originally on the form and the data inserted on the form

I found a VBA code online to build the timer and the form, I can start the timer, stop the timer, and add the time to the associated table. My problem comes in getting the record associated with the current form to be updated once I click the stop timer. Here's the code:

Code:
Private Sub cmdEnd_Click()
Dim rs As DAO.Recordset
Me.TimerInterval = 0
Set rs = CurrentDb.OpenRecordset("SELECT *" & _
    "FROM tblLog WHERE tblLog.LastName" & _
    "LIKE 'Brown';")
rs.Edit
rs!StartOfTest = Me.txtSessionStart
rs!EndOfTest = Now()
rs!ActualMinutes = Me.txtActualMinutes
rs!ActualSeconds = Me.txtActualSeconds
rs.Update
rs.Close
Set rs = Nothing
MsgBox "Data logged.", vbOKOnly, "Logged"
End Sub

This code will input the time data into the record associated with patient with the last name "Brown". However, I need the record associated with a text box control on the current form to be edited, not just change Mr. Brown's record every time.

I have tried:

Code:
Set rs = CurrentDb.OpenRecordset("SELECT *" & _
    "FROM tblLog WHERE tblLog.LastName" & _
    "LIKE 'Forms!frmDemo!tblePtInfo.LastName';")

Where frmDemo is the form where the timer is being run on which I inserted controls from a separate table (tblPtInfo) that has all of the same LastName records as the tblLog records. I am trying to reference the value on the current record displayed on the form and then edit the record in the tblLog with the same value.

When I use the above code I get "Syntax error (missing operator) in query expression 'tblLog.LastNameLike'Forms!frmDemo!LastName"

Any help would be hugely appreciated.
 
Proper way of doing SQL in code is described here: http://www.baldyweb.com/immediatewindow.htm Follow that routine and it will save you lots of grief.

Like 'smoething' is wasted and could be an equal sign.

If you mean a potential subset of the string then you need a "*" so

Like '*' & "something" or
Like 'something' & '*' or


and

"LIKE 'Forms!frmDemo!tblePtInfo.LastName';")

should be

"= ' " & Forms!frmDemo!tblePtInfo.LastName & "'")

with ' to wrap a string in SQL

and the string itself exposed.

Follow the recipe of PBaldy's and you'll see.
 
Set rs = CurrentDb.OpenRecordset("SELECT *" & _
"FROM tblLog WHERE tblLog.LastName" & _
"= '" & Forms!frmDemo!tblePtInfo.LastName & "';")

don't use "Like", be specific.
 

Users who are viewing this thread

Back
Top Bottom