G
Guest
I am interested in incrementing a control on my subform (called ‘DaysView’)
every time a user clicks a button on the main form (called ‘Screening Log
(Edit Only)’. The two forms are linked in a child (DaysView) /parent
(Screening Only (Edit Only) style using last name, first name, middle
initial, medical record number, and irb number (which represents which
experiment the said patient’s been screened for). I would really like to get
more VBA training and the discussion group has been a good stand-in so I
count myself as a non-expert VBA-er: far from it.
The code I wrote to perform the above (see below) doesn’t work as yet and is
based upon the need to increment a field in a similar way in the child form
of another parent form. When I click the button to add a record (on the
mainform) the following message shows up:
Oncology Screening Log can’t find the field ‘|’ referred to in your expression
That code did work and is pasted below the string of “=â€
It would be great if this could work. I’m sure if I could understand the
principle(s) involved which made it increment Visit by 1 each time, that that
would move me a notch up the ‘learning curve’. Any help’d be appreciated.
-ted
Private Sub Add_Record_Click()
On Error GoTo Err_Add_Record_Click
Dim sql As String
Dim lname As String
Dim fname As String
Dim MI As String
Dim mrnum As Long
Dim irbnum As String
Dim visnum As Integer
lname = [Forms]![Screening Log (Edit Only)]![Last Name]
fname = [Forms]![Screening Log (Edit Only)]![First Name]
m__i = [Forms]![Screening Log (Edit Only)]![MI]
mrnum = [Forms]![Screening Log (Edit Only)]![MR Number]
irbnum = [Forms]![Screening Log (Edit Only)]![IRB Number]
visnum = Nz(DMax("[RecordNumber]", "[DaysView]", "[Last Name] = """ & _
[LastName] & """ And [First Name] = """ & [First_Name] & """ And [MI] = """
& _
[M_I] & """ And [MR_Number] = " & [MRNumber] & " And [IRB Number] = """ & _
[IRBNumber] & """"), 0) + 1
sql = "INSERT INTO [DaysView] ([Last Name], [First Name],
[MI],[MR_Number],[IRB Number],[RecordNumber])" & "SELECT """ & lname & """
AS FN, """ & fname & """ AS FN, """ & m__i & """ AS MI, " & CStr(mrnum) & "
AS MR, """ & irbnum & """ AS IRB, " & visnum & " AS VIS;"
MsgBox sql
Dim db As Database
Set db = CurrentDb
db.Execute sql
Set db = Nothing
Me.Requery
Dim rs As Recordset
Set rs = Me.Recordset.Clone
'For some reason, in my current A2K mdb database Find (below) exists but
FindFirst does not!
rs.Find "[Last Name] = """ & lname & """ And [First Name] = """ & _
fname & """ And [MI] = """ & m__i & """ And [MR_Number] = " & CStr(mrnum) &
"" _
And [IRB Number] = """ & irbnum & """ And [RecordNumber] = " & CStr(visnum)
& "
Me.Bookmark = rs.Bookmark
Exit_Add_Record_Click:
Exit Sub
Err_Add_Record_Click:
MsgBox Err.description
Resume Exit_Add_Record_Click
End Sub
(This is the code I wrote in another A2K mdb database which does work)
Private Sub Add_Record_Click()
On Error GoTo Err_Add_Record_Click
Dim sql As String
Dim pn As Long
Dim ln As Integer
Dim upd As String
pn = [Forms]![RECIST Disease Evaluation: Target Lesions]![Patient Number]
ln = Nz(DMax("[Lesion Number]", "[Lesions: Target]", "[Patient Number] =
" _
& [Forms]![RECIST Disease Evaluation: Target Lesions]![Patient Number]),
0) + 1
upd = "New record added on " & Date & " at " & Time & " by " &
LAS_GetUserName() & ";"
sql = "INSERT INTO [Lesions: Target] ( [Patient Number], [Lesion
Number], [Updates_BL])" & _
"SELECT " & CStr(pn) & " AS PN, " & CStr(ln) & " AS LN ,""" & upd & """
AS UPD;"
' MsgBox sql
Dim db As Database
Set db = CurrentDb
db.Execute sql
Set db = Nothing
Me.Requery
Dim rs As Recordset
Set rs = Me.Recordset.Clone
rs.FindFirst "[Patient Number]=" & CStr(pn) & " and [Lesion Number]=" &
CStr(ln)
Me.Bookmark = rs.Bookmark
Exit_Add_Record_Click:
Exit Sub
Err_Add_Record_Click:
MsgBox Err.description
Resume Exit_Add_Record_Click
End Sub
every time a user clicks a button on the main form (called ‘Screening Log
(Edit Only)’. The two forms are linked in a child (DaysView) /parent
(Screening Only (Edit Only) style using last name, first name, middle
initial, medical record number, and irb number (which represents which
experiment the said patient’s been screened for). I would really like to get
more VBA training and the discussion group has been a good stand-in so I
count myself as a non-expert VBA-er: far from it.
The code I wrote to perform the above (see below) doesn’t work as yet and is
based upon the need to increment a field in a similar way in the child form
of another parent form. When I click the button to add a record (on the
mainform) the following message shows up:
Oncology Screening Log can’t find the field ‘|’ referred to in your expression
That code did work and is pasted below the string of “=â€
It would be great if this could work. I’m sure if I could understand the
principle(s) involved which made it increment Visit by 1 each time, that that
would move me a notch up the ‘learning curve’. Any help’d be appreciated.
-ted
Private Sub Add_Record_Click()
On Error GoTo Err_Add_Record_Click
Dim sql As String
Dim lname As String
Dim fname As String
Dim MI As String
Dim mrnum As Long
Dim irbnum As String
Dim visnum As Integer
lname = [Forms]![Screening Log (Edit Only)]![Last Name]
fname = [Forms]![Screening Log (Edit Only)]![First Name]
m__i = [Forms]![Screening Log (Edit Only)]![MI]
mrnum = [Forms]![Screening Log (Edit Only)]![MR Number]
irbnum = [Forms]![Screening Log (Edit Only)]![IRB Number]
visnum = Nz(DMax("[RecordNumber]", "[DaysView]", "[Last Name] = """ & _
[LastName] & """ And [First Name] = """ & [First_Name] & """ And [MI] = """
& _
[M_I] & """ And [MR_Number] = " & [MRNumber] & " And [IRB Number] = """ & _
[IRBNumber] & """"), 0) + 1
sql = "INSERT INTO [DaysView] ([Last Name], [First Name],
[MI],[MR_Number],[IRB Number],[RecordNumber])" & "SELECT """ & lname & """
AS FN, """ & fname & """ AS FN, """ & m__i & """ AS MI, " & CStr(mrnum) & "
AS MR, """ & irbnum & """ AS IRB, " & visnum & " AS VIS;"
MsgBox sql
Dim db As Database
Set db = CurrentDb
db.Execute sql
Set db = Nothing
Me.Requery
Dim rs As Recordset
Set rs = Me.Recordset.Clone
'For some reason, in my current A2K mdb database Find (below) exists but
FindFirst does not!
rs.Find "[Last Name] = """ & lname & """ And [First Name] = """ & _
fname & """ And [MI] = """ & m__i & """ And [MR_Number] = " & CStr(mrnum) &
"" _
And [IRB Number] = """ & irbnum & """ And [RecordNumber] = " & CStr(visnum)
& "
Me.Bookmark = rs.Bookmark
Exit_Add_Record_Click:
Exit Sub
Err_Add_Record_Click:
MsgBox Err.description
Resume Exit_Add_Record_Click
End Sub
(This is the code I wrote in another A2K mdb database which does work)
Private Sub Add_Record_Click()
On Error GoTo Err_Add_Record_Click
Dim sql As String
Dim pn As Long
Dim ln As Integer
Dim upd As String
pn = [Forms]![RECIST Disease Evaluation: Target Lesions]![Patient Number]
ln = Nz(DMax("[Lesion Number]", "[Lesions: Target]", "[Patient Number] =
" _
& [Forms]![RECIST Disease Evaluation: Target Lesions]![Patient Number]),
0) + 1
upd = "New record added on " & Date & " at " & Time & " by " &
LAS_GetUserName() & ";"
sql = "INSERT INTO [Lesions: Target] ( [Patient Number], [Lesion
Number], [Updates_BL])" & _
"SELECT " & CStr(pn) & " AS PN, " & CStr(ln) & " AS LN ,""" & upd & """
AS UPD;"
' MsgBox sql
Dim db As Database
Set db = CurrentDb
db.Execute sql
Set db = Nothing
Me.Requery
Dim rs As Recordset
Set rs = Me.Recordset.Clone
rs.FindFirst "[Patient Number]=" & CStr(pn) & " and [Lesion Number]=" &
CStr(ln)
Me.Bookmark = rs.Bookmark
Exit_Add_Record_Click:
Exit Sub
Err_Add_Record_Click:
MsgBox Err.description
Resume Exit_Add_Record_Click
End Sub