Error 3021 No Current Record

K

Ken Snell [MVP]

You may be very correct that there is some other issue involved here. We
don't know what those other forms do (where you say the code is working
fine), and we don't have any knowledge of the form's structure, the purpose
and use of the forms, etc.

Our answers are based on the questions that you're asking and the errors
that you're experiencing and the code that you've provided. We're probing
here with our responses and suggestions, but, based on what I have read in
this thread, I know that I am unable to give you an absolutely accurate
answer to your question about what might be overlooked. The last code
example that I suggested is a correct syntax for inserting a record,
requerying a form's recordsource, and then moving the form to a specific
record (if that record exists) in the form's recordsource.
 
K

Ken Snell [MVP]

Marshall Barton said:
Ted wrote:

Another point. I see you removed the CStr functions, but
you added extra quotes inplace of it. The quotes should
cause a type mismatch error, since you said the two fields
are numeric.

That was my error, Marsh. I hadn't realized that the fields were numeric.
 
G

Guest

i think i need to take back what i said about the Protocol Title and ID
fields. i did some further snooping and noted that they AREN'T present in the
working scenario i keep referring us to but ARE required in this one. so i'm
borrowing if that is the word the relevant snippets of vba code in the onopen
event of the Concomitant Medications' form and trying to fiddle them into the
'SELECT' statement. my current evolution has this code so far

Private Sub Add_Record_DblClick(Cancel As Integer)
On Error GoTo Err_Add_Record_DblClick
Dim sql As String
Dim pn As Long
Dim mn As Integer
Dim db As Database
Dim rs As DAO.Recordset

Set db = CurrentDb
pn = [Forms]![Command and Control Center]![SelectPatient]
mn = Nz(DMax("[Med Number]", "[Concomitant Medications]", "[Patient
Number] = " _
& [Forms]![Command and Control Center]![SelectPatient]), 0) + 1

sql = "INSERT INTO [Concomitant Medications] ([Patient Number], [Med
Number])" & _
"SELECT " & pn & " , " & mn & " , " & Me.Protocol_ID.DefaultValue =
DLookup("ProtocolID", "tblDefaults") & " , " & _
Me.Protocol_Title.DefaultValue = """" & DLookup("ProtocolTitle",
"tblDefaults") & """" & " ;"

db.Execute sql, dbFailOnError

Me.Requery

Set rs = Me.RecordsetClone
rs.FindFirst "[Patient Number]= " & pn & " and [Med Number] = " & mn & " "

If rs.NoMatch Then
MsgBox "something's wrong"

Else
Me.Bookmark = rs.Bookmark
End If

Exit_Add_Record_DblClick:
Set rs = Nothing
Set db = Nothing
Exit Sub

Err_Add_Record_DblClick:
MsgBox Err.Number & " = " & Err.description
Resume Exit_Add_Record_DblClick

End Sub

which is compiling 'OK' but resulting in this cryptic message:

"3078 = The Microsoft Jet database engine cannot find the input table or
query 'False'. Make sure it exists and that its name is spelled correctly".

i noted when i hovered the cursor over the 'sql' word in the 'sql = '
statement that it's equal to 'False' which is bound to be where this is
coming from....

-ted







Ken Snell said:
Sounds as if you need to include the Protocol ID field in your append query.
Not sure if the subform's code is generating a valid value for you to use,
as I am not understanding your form's setup.

However, assuming that you can get the necessary value for Protocol ID, your
append query should be changed to something like this (replace the string
"The Protocol ID Value" with a reference to a control that has this value,
or with the actual value as a constant, or something):

sql = "INSERT INTO [Concomitant Medications] ([Patient Number], [Med
Number], [Protocol ID])" & _
"SELECT '" & pn & "', '" & mn & "', " & "The Protocol ID Value" & ";"

--

Ken Snell
<MS ACCESS MVP>

Ted said:
well ken, this is getting really interesting. we've removed the 424 error
only to have it replaced with

"3314 = The field 'Concomitant Medications.Protocol ID' cannot contain a
Null value because the Required property for the field isset to True.
Enter a
value in this field".


i don't know whether this helps, hopefully it does, but in the
subform-open
code i pasted in my earlier, there's some relevant looing code

Fill in Protocol ID value
Me.Protocol_ID.DefaultValue = DLookup("ProtocolID",
"tblDefaults")

' Fill in Protocol Title
Me.Protocol_Title.DefaultValue = """" & _
DLookup("ProtocolTitle", "tblDefaults") & """"
End If

-ted



Ken Snell said:
Aha... my eyes are getting worse as I age....

Your code never sets ds variable to any object.

Try this modified code:
-----------------------

Private Sub Add_Record_DblClick(Cancel As Integer)
On Error GoTo Err_Add_Record_DblClick
Dim sql As String
Dim pn As Long
Dim mn As Integer
Dim db As Database
Dim rs As DAO.Recordset

Set db = CurrentDb
pn = [Forms]![Command and Control Center]![SelectPatient]
mn = Nz(DMax("[Med Number]", "[Concomitant Medications]", "[Patient
Number] = " _
& [Forms]![Command and Control Center]![SelectPatient]), 0) + 1

sql = "INSERT INTO [Concomitant Medications] ([Patient Number], [Med
Number])" & _
"SELECT '" & pn & "', '" & mn & "';"

db.Execute sql, dbFailOnError

Me.Requery

Set rs = Me.RecordsetClone
rs.FindFirst "[Patient Number]='" & pn & "' and [Med Number] = '" & mn
&
"'"

If rs.NoMatch Then
MsgBox "something's wrong"

Else
Me.Bookmark = rs.Bookmark
End If

Exit_Add_Record_DblClick:
Set rs = Nothing
Set db = Nothing
Exit Sub

Err_Add_Record_DblClick:
MsgBox Err.Number & " = " & Err.description
Resume Exit_Add_Record_DblClick

End Sub


--

Ken Snell
<MS ACCESS MVP>



i will try and intersperse my responses where they would naturally flow
ken.


:

Let me back up.

I reviewed the thread and didn't find that you identified the exact
line
on
which the error 424 is occurring? Can you identify that step?

w/ my breakpoint on the 'pn' statement atop this, i 'F8' my way one
step @
a time and when the yellow highlight is on the " ds.Execute sql,
dbFailOnerror" line as i 'F8' it jumps to the MsgBox Err.Number & " =
" &
Err.description line.


What is the RecordSource query of the form in which this code is
running?

IT IS A TABLE AND ITS NAMED 'Concomitant Medications'.

If
it's a table, please indicate the fields that are in that table?

THERE ARE MANY MANY FIELDS IN THAT TABLE. "Patient Number" and "Med
Number"
are the two which make up the composite PK (in that same order). DO YOU
REQUIRE A LIST OF ALL THE FIELDS TO ANSWER YOUR QUESTION. I WILL
PROVIDE
IT
IF ABSOLUTELY NEEDED.

Is the form
filtered in any way when it's opened (in the DoCmd.OpenForm action)?


YES IT IS FILTERED. IT'S FILTERED VIA THE CODE BELOW

Private Sub Form_Open(Cancel As Integer)
On Error GoTo Error_Handler

' Using "ApplyFilter" and "Ted" search string
' on MS discussion groups (3/16/2005 and 3/21/05)

If IsNull(Forms![Command and Control Center]!SelectPatient) _
Then
' No Patient ID entered on main form
MsgBox "Please select a Patient Number from " _
& "the list provided before continuing." _
, vbInformation, "Which Patient?"
' Stop the form from opening
Cancel = True
Else
' Check to see if Final Answer has been entered
If DLookup("FinalAnswer", "tblDefaults") = False Then
' Missing information
MsgBox "The correct Protocol ID and Title have not " _
& "been entered into the database." & vbNewLine _
& "Notify the Administrator. At this time you can " _
& "not enter data into the database.", 64 _
, "Warning -- Read Before Proceeding!"
' Stop the form from opening
Cancel = True
Else
' All clear, continue with form opening
' Patient ID was selected on main form

' Run Security Code
LAS_EnableSecurity Me

' Maximize the form
DoCmd.Maximize

' Apply a filter to match chosen Patient Number and set
DoCmd.ApplyFilter , "[Patient Number] = " & _
[Forms]![Command and Control Center]![SelectPatient]

' Fill in Protocol ID value
Me.Protocol_ID.DefaultValue = DLookup("ProtocolID",
"tblDefaults")

' Fill in Protocol Title
Me.Protocol_Title.DefaultValue = """" & _
DLookup("ProtocolTitle", "tblDefaults") & """"
End If
End If

ExitPoint:
Exit Sub

Error_Handler:
If Err.Number = 2467 Then
' Ignore
Else
' Unexpected Error
MsgBox "An unanticipated error has occurred." & _
"The error number is " & Err.Number & _
" and the description is '" & Err.description & "'" & _
" Please contact your System Administrator."
End If
Resume ExitPoint

End Sub



And let me confirm.. this error is occurring only when your form has
no
records in it?

THIS OCCURS WHETHER OR NOT THE FORM HAS RECORDS IN IT.

HTH

-ted


--

Ken Snell
<MS ACCESS MVP>


hi ken,

using my best copy and paste strategies, the code i'm using (and
i'll
tell
you in one shake of a lamb's tail how it's failing) is as under
(with a
breakpoint on 'pn')

Private Sub Add_Record_DblClick(Cancel As Integer)
On Error GoTo Err_Add_Record_DblClick
Dim sql As String
Dim pn As Long
Dim mn As Integer

pn = [Forms]![Command and Control Center]![SelectPatient]
mn = Nz(DMax("[Med Number]", "[Concomitant Medications]", "[Patient
Number] = " _
& [Forms]![Command and Control Center]![SelectPatient]), 0) + 1

sql = "INSERT INTO [Concomitant Medications] ([Patient Number],
[MedNumber])" & _
"SELECT '" & pn & "', '" & mn & "';"

ds.Execute sql, dbFailOnError


Dim db As Database
Set db = CurrentDb
db.Execute sql

Set db = Nothing

Me.Requery

Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
rs.FindFirst "[Patient Number]='" & pn & "' and [Med Number] = '" &
mn
&
"'"

If rs.NoMatch Then
MsgBox "something's wrong"

Else
Me.Bookmark = rs.Bookmark
End If

Exit_Add_Record_DblClick:
Set rs = Nothing
Exit Sub

Err_Add_Record_DblClick:
MsgBox Err.Number & " = " & Err.description
Resume Exit_Add_Record_DblClick

End Sub

so as i "F8" my way, i find the same "424 = Object required" error's
showing
itself :-(

-ted

:

You didn't change to Me.RecordsetClone in your code; you're still
using
Me.Recordset.Clone.

Also, your INSERT INTO string is going to fail when you try to
execute
it
because you're not delimiting the string values with ' characters
when
you
build the SQL string.

Similarly, the FindFirst step will fail without ' characters.


Try this modified code:
-----------------------

Private Sub Add_Record_DblClick(Cancel As Integer)
On Error GoTo Err_Add_Record_DblClick
Dim sql As String
Dim pn As Long
Dim mn As Integer

pn = [Forms]![Command and Control Center]![SelectPatient]
mn = Nz(DMax("[Med Number]", "[Concomitant Medications]",
"[Patient
Number] = " _
& [Forms]![Command and Control Center]![SelectPatient]), 0) + 1

sql = "INSERT INTO [Concomitant Medications] ([Patient Number],
[Med
Number])" & _
"SELECT '" & pn & "', '" & mn & "';"

ds.Execute sql, dbFailOnError


Dim db As Database
Set db = CurrentDb
db.Execute sql

Set db = Nothing

Me.Requery

Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
rs.FindFirst "[Patient Number]='" & pn & "' and [Med Number] = '"
&
mn
&
"'"

If rs.NoMatch Then
MsgBox "something's wrong"

Else
Me.Bookmark = rs.Bookmark
End If

Exit_Add_Record_DblClick:
Set rs = Nothing
Exit Sub

Err_Add_Record_DblClick:
MsgBox Err.Number & " = " & Err.description
Resume Exit_Add_Record_DblClick

End Sub


--

Ken Snell
<MS ACCESS MVP>

hi ken,

using the vba (below) it matters not whether i use one or the
other,
it's
now giving me a "424 = Object required" error message. i put a
breakpoint
on
the 'pn = ' statement and i "F8"ed my way down the code where i
see
it
jump
to the statement which displays the said 424 msg :-(

Private Sub Add_Record_DblClick(Cancel As Integer)
On Error GoTo Err_Add_Record_DblClick
Dim sql As String
Dim pn As Long
Dim mn As Integer

pn = [Forms]![Command and Control Center]![SelectPatient]
mn = Nz(DMax("[Med Number]", "[Concomitant Medications]",
"[Patient
Number] = " _
& [Forms]![Command and Control Center]![SelectPatient]), 0) + 1

sql = "INSERT INTO [Concomitant Medications] ([Patient Number],
[Med
Number])" & _
"SELECT " & CStr(pn) & " AS PN, " & CStr(mn) & " AS MN;"

ds.Execute sql, dbFailOnError


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 [Med Number]
=
" &
CStr(mn)

If rs.NoMatch Then
MsgBox "something's wrong"
End If

Me.Bookmark = rs.Bookmark

Exit_Add_Record_DblClick:
Exit Sub

Err_Add_Record_DblClick:
MsgBox Err.Number & " = " & Err.description
Resume Exit_Add_Record_DblClick

End Sub

-ted



:

Use Me.RecordsetClone recordset, not Me.Recordset.Clone
recordset.

--

Ken Snell
<MS ACCESS MVP>

so, ken....where's all this leave yours truly?

-ted


:

Hmmmm.... but the Help files say that the bookmarks are
compatible:

"Use the Clone method to create multiple, duplicate Recordset
objects.
Each
Recordset can have its own current record. Using Clone by
itself
doesn't
change the data in the objects or in their underlying
structures.
When
you
use the Clone method, you can share bookmarks between two or
more
Recordset
objects because their bookmarks are interchangeable."

I then tried the setup using two separate clone recordsets of
the
form's
recordset. When trying to set one of the clone's bookmark to
the
bookmark
of
the other clone, I still get the Type Mismatch error.

So the Help files appear to be incorrect for this use of
Clone
method
of
a
form's recordset.

--

Ken Snell
<MS ACCESS MVP>


message
In my test, I get a Type Mismatch error when trying to set
the
form's
Bookmark (Me.Bookmark) to the recordset's bookmark
(rst.Bookmark)
when
rst
is the Recordset.Clone.

Marsh correctly points out that you should be using
RecordsetClone,
not
Recordset.Clone, in your code.
 
K

Ken Snell [MVP]

You've "dropped" into your expression two entire code steps as if they were
values. And that means that the code calculates a "true/false" comparison
because you have additonal = signs in the code.

You also have only two target fields (Patient Number and Med Number) in your
append query, but you're trying to add four separate values (from pn, mn,
something about protocol id, and something about protocoltitle)?

Are you looking at what you're doing in your code construction?

I think that suggesting more changes to your code is just causing us to spin
our wheels. Can you tell us in words just what it is that you want this code
to do? What fields are being populated in the append query? from where do
the values for those fields come? and so on?
--

Ken Snell
<MS ACCESS MVP>



Ted said:
i think i need to take back what i said about the Protocol Title and ID
fields. i did some further snooping and noted that they AREN'T present in
the
working scenario i keep referring us to but ARE required in this one. so
i'm
borrowing if that is the word the relevant snippets of vba code in the
onopen
event of the Concomitant Medications' form and trying to fiddle them into
the
'SELECT' statement. my current evolution has this code so far

Private Sub Add_Record_DblClick(Cancel As Integer)
On Error GoTo Err_Add_Record_DblClick
Dim sql As String
Dim pn As Long
Dim mn As Integer
Dim db As Database
Dim rs As DAO.Recordset

Set db = CurrentDb
pn = [Forms]![Command and Control Center]![SelectPatient]
mn = Nz(DMax("[Med Number]", "[Concomitant Medications]", "[Patient
Number] = " _
& [Forms]![Command and Control Center]![SelectPatient]), 0) + 1

sql = "INSERT INTO [Concomitant Medications] ([Patient Number], [Med
Number])" & _
"SELECT " & pn & " , " & mn & " , " & Me.Protocol_ID.DefaultValue =
DLookup("ProtocolID", "tblDefaults") & " , " & _
Me.Protocol_Title.DefaultValue = """" & DLookup("ProtocolTitle",
"tblDefaults") & """" & " ;"

db.Execute sql, dbFailOnError

Me.Requery

Set rs = Me.RecordsetClone
rs.FindFirst "[Patient Number]= " & pn & " and [Med Number] = " & mn &
" "

If rs.NoMatch Then
MsgBox "something's wrong"

Else
Me.Bookmark = rs.Bookmark
End If

Exit_Add_Record_DblClick:
Set rs = Nothing
Set db = Nothing
Exit Sub

Err_Add_Record_DblClick:
MsgBox Err.Number & " = " & Err.description
Resume Exit_Add_Record_DblClick

End Sub

which is compiling 'OK' but resulting in this cryptic message:

"3078 = The Microsoft Jet database engine cannot find the input table or
query 'False'. Make sure it exists and that its name is spelled
correctly".

i noted when i hovered the cursor over the 'sql' word in the 'sql = '
statement that it's equal to 'False' which is bound to be where this is
coming from....

-ted







Ken Snell said:
Sounds as if you need to include the Protocol ID field in your append
query.
Not sure if the subform's code is generating a valid value for you to
use,
as I am not understanding your form's setup.

However, assuming that you can get the necessary value for Protocol ID,
your
append query should be changed to something like this (replace the string
"The Protocol ID Value" with a reference to a control that has this
value,
or with the actual value as a constant, or something):

sql = "INSERT INTO [Concomitant Medications] ([Patient Number], [Med
Number], [Protocol ID])" & _
"SELECT '" & pn & "', '" & mn & "', " & "The Protocol ID Value" & ";"

--

Ken Snell
<MS ACCESS MVP>

Ted said:
well ken, this is getting really interesting. we've removed the 424
error
only to have it replaced with

"3314 = The field 'Concomitant Medications.Protocol ID' cannot contain
a
Null value because the Required property for the field isset to True.
Enter a
value in this field".


i don't know whether this helps, hopefully it does, but in the
subform-open
code i pasted in my earlier, there's some relevant looing code

Fill in Protocol ID value
Me.Protocol_ID.DefaultValue = DLookup("ProtocolID",
"tblDefaults")

' Fill in Protocol Title
Me.Protocol_Title.DefaultValue = """" & _
DLookup("ProtocolTitle", "tblDefaults") & """"
End If

-ted



:

Aha... my eyes are getting worse as I age....

Your code never sets ds variable to any object.

Try this modified code:
-----------------------

Private Sub Add_Record_DblClick(Cancel As Integer)
On Error GoTo Err_Add_Record_DblClick
Dim sql As String
Dim pn As Long
Dim mn As Integer
Dim db As Database
Dim rs As DAO.Recordset

Set db = CurrentDb
pn = [Forms]![Command and Control Center]![SelectPatient]
mn = Nz(DMax("[Med Number]", "[Concomitant Medications]", "[Patient
Number] = " _
& [Forms]![Command and Control Center]![SelectPatient]), 0) + 1

sql = "INSERT INTO [Concomitant Medications] ([Patient Number], [Med
Number])" & _
"SELECT '" & pn & "', '" & mn & "';"

db.Execute sql, dbFailOnError

Me.Requery

Set rs = Me.RecordsetClone
rs.FindFirst "[Patient Number]='" & pn & "' and [Med Number] = '" &
mn
&
"'"

If rs.NoMatch Then
MsgBox "something's wrong"

Else
Me.Bookmark = rs.Bookmark
End If

Exit_Add_Record_DblClick:
Set rs = Nothing
Set db = Nothing
Exit Sub

Err_Add_Record_DblClick:
MsgBox Err.Number & " = " & Err.description
Resume Exit_Add_Record_DblClick

End Sub


--

Ken Snell
<MS ACCESS MVP>



i will try and intersperse my responses where they would naturally
flow
ken.


:

Let me back up.

I reviewed the thread and didn't find that you identified the exact
line
on
which the error 424 is occurring? Can you identify that step?

w/ my breakpoint on the 'pn' statement atop this, i 'F8' my way one
step @
a time and when the yellow highlight is on the " ds.Execute sql,
dbFailOnerror" line as i 'F8' it jumps to the MsgBox Err.Number & "
=
" &
Err.description line.


What is the RecordSource query of the form in which this code is
running?

IT IS A TABLE AND ITS NAMED 'Concomitant Medications'.

If
it's a table, please indicate the fields that are in that table?

THERE ARE MANY MANY FIELDS IN THAT TABLE. "Patient Number" and "Med
Number"
are the two which make up the composite PK (in that same order). DO
YOU
REQUIRE A LIST OF ALL THE FIELDS TO ANSWER YOUR QUESTION. I WILL
PROVIDE
IT
IF ABSOLUTELY NEEDED.

Is the form
filtered in any way when it's opened (in the DoCmd.OpenForm
action)?


YES IT IS FILTERED. IT'S FILTERED VIA THE CODE BELOW

Private Sub Form_Open(Cancel As Integer)
On Error GoTo Error_Handler

' Using "ApplyFilter" and "Ted" search string
' on MS discussion groups (3/16/2005 and 3/21/05)

If IsNull(Forms![Command and Control Center]!SelectPatient) _
Then
' No Patient ID entered on main form
MsgBox "Please select a Patient Number from " _
& "the list provided before continuing." _
, vbInformation, "Which Patient?"
' Stop the form from opening
Cancel = True
Else
' Check to see if Final Answer has been entered
If DLookup("FinalAnswer", "tblDefaults") = False Then
' Missing information
MsgBox "The correct Protocol ID and Title have not " _
& "been entered into the database." & vbNewLine _
& "Notify the Administrator. At this time you can " _
& "not enter data into the database.", 64 _
, "Warning -- Read Before Proceeding!"
' Stop the form from opening
Cancel = True
Else
' All clear, continue with form opening
' Patient ID was selected on main form

' Run Security Code
LAS_EnableSecurity Me

' Maximize the form
DoCmd.Maximize

' Apply a filter to match chosen Patient Number and set
DoCmd.ApplyFilter , "[Patient Number] = " & _
[Forms]![Command and Control Center]![SelectPatient]

' Fill in Protocol ID value
Me.Protocol_ID.DefaultValue = DLookup("ProtocolID",
"tblDefaults")

' Fill in Protocol Title
Me.Protocol_Title.DefaultValue = """" & _
DLookup("ProtocolTitle", "tblDefaults") & """"
End If
End If

ExitPoint:
Exit Sub

Error_Handler:
If Err.Number = 2467 Then
' Ignore
Else
' Unexpected Error
MsgBox "An unanticipated error has occurred." & _
"The error number is " & Err.Number & _
" and the description is '" & Err.description & "'" & _
" Please contact your System Administrator."
End If
Resume ExitPoint

End Sub



And let me confirm.. this error is occurring only when your form
has
no
records in it?

THIS OCCURS WHETHER OR NOT THE FORM HAS RECORDS IN IT.

HTH

-ted


--

Ken Snell
<MS ACCESS MVP>


hi ken,

using my best copy and paste strategies, the code i'm using (and
i'll
tell
you in one shake of a lamb's tail how it's failing) is as under
(with a
breakpoint on 'pn')

Private Sub Add_Record_DblClick(Cancel As Integer)
On Error GoTo Err_Add_Record_DblClick
Dim sql As String
Dim pn As Long
Dim mn As Integer

pn = [Forms]![Command and Control Center]![SelectPatient]
mn = Nz(DMax("[Med Number]", "[Concomitant Medications]",
"[Patient
Number] = " _
& [Forms]![Command and Control Center]![SelectPatient]), 0) + 1

sql = "INSERT INTO [Concomitant Medications] ([Patient Number],
[MedNumber])" & _
"SELECT '" & pn & "', '" & mn & "';"

ds.Execute sql, dbFailOnError


Dim db As Database
Set db = CurrentDb
db.Execute sql

Set db = Nothing

Me.Requery

Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
rs.FindFirst "[Patient Number]='" & pn & "' and [Med Number] =
'" &
mn
&
"'"

If rs.NoMatch Then
MsgBox "something's wrong"

Else
Me.Bookmark = rs.Bookmark
End If

Exit_Add_Record_DblClick:
Set rs = Nothing
Exit Sub

Err_Add_Record_DblClick:
MsgBox Err.Number & " = " & Err.description
Resume Exit_Add_Record_DblClick

End Sub

so as i "F8" my way, i find the same "424 = Object required"
error's
showing
itself :-(

-ted

:

You didn't change to Me.RecordsetClone in your code; you're
still
using
Me.Recordset.Clone.

Also, your INSERT INTO string is going to fail when you try to
execute
it
because you're not delimiting the string values with '
characters
when
you
build the SQL string.

Similarly, the FindFirst step will fail without ' characters.


Try this modified code:
-----------------------

Private Sub Add_Record_DblClick(Cancel As Integer)
On Error GoTo Err_Add_Record_DblClick
Dim sql As String
Dim pn As Long
Dim mn As Integer

pn = [Forms]![Command and Control Center]![SelectPatient]
mn = Nz(DMax("[Med Number]", "[Concomitant Medications]",
"[Patient
Number] = " _
& [Forms]![Command and Control Center]![SelectPatient]), 0) +
1

sql = "INSERT INTO [Concomitant Medications] ([Patient
Number],
[Med
Number])" & _
"SELECT '" & pn & "', '" & mn & "';"

ds.Execute sql, dbFailOnError


Dim db As Database
Set db = CurrentDb
db.Execute sql

Set db = Nothing

Me.Requery

Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
rs.FindFirst "[Patient Number]='" & pn & "' and [Med Number] =
'"
&
mn
&
"'"

If rs.NoMatch Then
MsgBox "something's wrong"

Else
Me.Bookmark = rs.Bookmark
End If

Exit_Add_Record_DblClick:
Set rs = Nothing
Exit Sub

Err_Add_Record_DblClick:
MsgBox Err.Number & " = " & Err.description
Resume Exit_Add_Record_DblClick

End Sub


--

Ken Snell
<MS ACCESS MVP>

hi ken,

using the vba (below) it matters not whether i use one or the
other,
it's
now giving me a "424 = Object required" error message. i put a
breakpoint
on
the 'pn = ' statement and i "F8"ed my way down the code where
i
see
it
jump
to the statement which displays the said 424 msg :-(

Private Sub Add_Record_DblClick(Cancel As Integer)
On Error GoTo Err_Add_Record_DblClick
Dim sql As String
Dim pn As Long
Dim mn As Integer

pn = [Forms]![Command and Control Center]![SelectPatient]
mn = Nz(DMax("[Med Number]", "[Concomitant Medications]",
"[Patient
Number] = " _
& [Forms]![Command and Control Center]![SelectPatient]), 0) +
1

sql = "INSERT INTO [Concomitant Medications] ([Patient
Number],
[Med
Number])" & _
"SELECT " & CStr(pn) & " AS PN, " & CStr(mn) & " AS MN;"

ds.Execute sql, dbFailOnError


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 [Med
Number]
=
" &
CStr(mn)

If rs.NoMatch Then
MsgBox "something's wrong"
End If

Me.Bookmark = rs.Bookmark

Exit_Add_Record_DblClick:
Exit Sub

Err_Add_Record_DblClick:
MsgBox Err.Number & " = " & Err.description
Resume Exit_Add_Record_DblClick

End Sub

-ted



:

Use Me.RecordsetClone recordset, not Me.Recordset.Clone
recordset.

--

Ken Snell
<MS ACCESS MVP>

so, ken....where's all this leave yours truly?

-ted


:

Hmmmm.... but the Help files say that the bookmarks are
compatible:

"Use the Clone method to create multiple, duplicate
Recordset
objects.
Each
Recordset can have its own current record. Using Clone by
itself
doesn't
change the data in the objects or in their underlying
structures.
When
you
use the Clone method, you can share bookmarks between two
or
more
Recordset
objects because their bookmarks are interchangeable."

I then tried the setup using two separate clone recordsets
of
the
form's
recordset. When trying to set one of the clone's bookmark
to
the
bookmark
of
the other clone, I still get the Type Mismatch error.

So the Help files appear to be incorrect for this use of
Clone
method
of
a
form's recordset.

--

Ken Snell
<MS ACCESS MVP>


in
message
In my test, I get a Type Mismatch error when trying to
set
the
form's
Bookmark (Me.Bookmark) to the recordset's bookmark
(rst.Bookmark)
when
rst
is the Recordset.Clone.

Marsh correctly points out that you should be using
RecordsetClone,
not
Recordset.Clone, in your code.
 
G

Guest

i will intersperse my responses below

Ken Snell said:
You've "dropped" into your expression two entire code steps as if they were
values. And that means that the code calculates a "true/false" comparison
because you have additonal = signs in the code.

i'm trying my darndest to appease the sql deities, honest. (so this is what
insanity feels like).
You also have only two target fields (Patient Number and Med Number) in your
append query, but you're trying to add four separate values (from pn, mn,
something about protocol id, and something about protocoltitle)?

whose eyes are getting tired? i guess i forgot about that part. so, correct
me if i'm wrong, but if the table's arranged "Protocol ID", "Protocol Title",
"Patient Number", "Med Number", etc. etc., then the append and select
statements need reflect the same arrangement ?

Are you looking at what you're doing in your code construction?

maybe i need an extra pair of orbs. i'm going into the deeper end of the pool.
I think that suggesting more changes to your code is just causing us to spin
our wheels. Can you tell us in words just what it is that you want this code
to do? What fields are being populated in the append query? from where do
the values for those fields come? and so on?

well, what's different about this Concomitant Medications form/table vs the
one where that vba code worked so nicely looks like is due to the presence of
the two extra fields Protocol ID and Title. these two fields are being filled
in , or should i say 'were', being filled in in the form on open event
property where i had some vba code telling the form where to fetch them from.

with the onset of the error messages i documented, it occured to me that the
portions of the vba code from the onopen event could be somehow added to the
SELECT clause which is actuated by the AddRecord button.

you would not be entirely wrong if you said i could use some more help w/
that.

does this make sense.

i can fill in any more gaps.



Ken Snell
<MS ACCESS MVP>



Ted said:
i think i need to take back what i said about the Protocol Title and ID
fields. i did some further snooping and noted that they AREN'T present in
the
working scenario i keep referring us to but ARE required in this one. so
i'm
borrowing if that is the word the relevant snippets of vba code in the
onopen
event of the Concomitant Medications' form and trying to fiddle them into
the
'SELECT' statement. my current evolution has this code so far

Private Sub Add_Record_DblClick(Cancel As Integer)
On Error GoTo Err_Add_Record_DblClick
Dim sql As String
Dim pn As Long
Dim mn As Integer
Dim db As Database
Dim rs As DAO.Recordset

Set db = CurrentDb
pn = [Forms]![Command and Control Center]![SelectPatient]
mn = Nz(DMax("[Med Number]", "[Concomitant Medications]", "[Patient
Number] = " _
& [Forms]![Command and Control Center]![SelectPatient]), 0) + 1

sql = "INSERT INTO [Concomitant Medications] ([Patient Number], [Med
Number])" & _
"SELECT " & pn & " , " & mn & " , " & Me.Protocol_ID.DefaultValue =
DLookup("ProtocolID", "tblDefaults") & " , " & _
Me.Protocol_Title.DefaultValue = """" & DLookup("ProtocolTitle",
"tblDefaults") & """" & " ;"

db.Execute sql, dbFailOnError

Me.Requery

Set rs = Me.RecordsetClone
rs.FindFirst "[Patient Number]= " & pn & " and [Med Number] = " & mn &
" "

If rs.NoMatch Then
MsgBox "something's wrong"

Else
Me.Bookmark = rs.Bookmark
End If

Exit_Add_Record_DblClick:
Set rs = Nothing
Set db = Nothing
Exit Sub

Err_Add_Record_DblClick:
MsgBox Err.Number & " = " & Err.description
Resume Exit_Add_Record_DblClick

End Sub

which is compiling 'OK' but resulting in this cryptic message:

"3078 = The Microsoft Jet database engine cannot find the input table or
query 'False'. Make sure it exists and that its name is spelled
correctly".

i noted when i hovered the cursor over the 'sql' word in the 'sql = '
statement that it's equal to 'False' which is bound to be where this is
coming from....

-ted







Ken Snell said:
Sounds as if you need to include the Protocol ID field in your append
query.
Not sure if the subform's code is generating a valid value for you to
use,
as I am not understanding your form's setup.

However, assuming that you can get the necessary value for Protocol ID,
your
append query should be changed to something like this (replace the string
"The Protocol ID Value" with a reference to a control that has this
value,
or with the actual value as a constant, or something):

sql = "INSERT INTO [Concomitant Medications] ([Patient Number], [Med
Number], [Protocol ID])" & _
"SELECT '" & pn & "', '" & mn & "', " & "The Protocol ID Value" & ";"

--

Ken Snell
<MS ACCESS MVP>

well ken, this is getting really interesting. we've removed the 424
error
only to have it replaced with

"3314 = The field 'Concomitant Medications.Protocol ID' cannot contain
a
Null value because the Required property for the field isset to True.
Enter a
value in this field".


i don't know whether this helps, hopefully it does, but in the
subform-open
code i pasted in my earlier, there's some relevant looing code

Fill in Protocol ID value
Me.Protocol_ID.DefaultValue = DLookup("ProtocolID",
"tblDefaults")

' Fill in Protocol Title
Me.Protocol_Title.DefaultValue = """" & _
DLookup("ProtocolTitle", "tblDefaults") & """"
End If

-ted



:

Aha... my eyes are getting worse as I age....

Your code never sets ds variable to any object.

Try this modified code:
-----------------------

Private Sub Add_Record_DblClick(Cancel As Integer)
On Error GoTo Err_Add_Record_DblClick
Dim sql As String
Dim pn As Long
Dim mn As Integer
Dim db As Database
Dim rs As DAO.Recordset

Set db = CurrentDb
pn = [Forms]![Command and Control Center]![SelectPatient]
mn = Nz(DMax("[Med Number]", "[Concomitant Medications]", "[Patient
Number] = " _
& [Forms]![Command and Control Center]![SelectPatient]), 0) + 1

sql = "INSERT INTO [Concomitant Medications] ([Patient Number], [Med
Number])" & _
"SELECT '" & pn & "', '" & mn & "';"

db.Execute sql, dbFailOnError

Me.Requery

Set rs = Me.RecordsetClone
rs.FindFirst "[Patient Number]='" & pn & "' and [Med Number] = '" &
mn
&
"'"

If rs.NoMatch Then
MsgBox "something's wrong"

Else
Me.Bookmark = rs.Bookmark
End If

Exit_Add_Record_DblClick:
Set rs = Nothing
Set db = Nothing
Exit Sub

Err_Add_Record_DblClick:
MsgBox Err.Number & " = " & Err.description
Resume Exit_Add_Record_DblClick

End Sub


--

Ken Snell
<MS ACCESS MVP>



i will try and intersperse my responses where they would naturally
flow
ken.


:

Let me back up.

I reviewed the thread and didn't find that you identified the exact
line
on
which the error 424 is occurring? Can you identify that step?

w/ my breakpoint on the 'pn' statement atop this, i 'F8' my way one
step @
a time and when the yellow highlight is on the " ds.Execute sql,
dbFailOnerror" line as i 'F8' it jumps to the MsgBox Err.Number & "
=
" &
Err.description line.


What is the RecordSource query of the form in which this code is
running?

IT IS A TABLE AND ITS NAMED 'Concomitant Medications'.

If
it's a table, please indicate the fields that are in that table?

THERE ARE MANY MANY FIELDS IN THAT TABLE. "Patient Number" and "Med
Number"
are the two which make up the composite PK (in that same order). DO
YOU
REQUIRE A LIST OF ALL THE FIELDS TO ANSWER YOUR QUESTION. I WILL
PROVIDE
IT
IF ABSOLUTELY NEEDED.

Is the form
filtered in any way when it's opened (in the DoCmd.OpenForm
action)?


YES IT IS FILTERED. IT'S FILTERED VIA THE CODE BELOW

Private Sub Form_Open(Cancel As Integer)
On Error GoTo Error_Handler

' Using "ApplyFilter" and "Ted" search string
' on MS discussion groups (3/16/2005 and 3/21/05)

If IsNull(Forms![Command and Control Center]!SelectPatient) _
Then
' No Patient ID entered on main form
MsgBox "Please select a Patient Number from " _
& "the list provided before continuing." _
, vbInformation, "Which Patient?"
' Stop the form from opening
Cancel = True
Else
' Check to see if Final Answer has been entered
If DLookup("FinalAnswer", "tblDefaults") = False Then
' Missing information
MsgBox "The correct Protocol ID and Title have not " _
& "been entered into the database." & vbNewLine _
& "Notify the Administrator. At this time you can " _
& "not enter data into the database.", 64 _
, "Warning -- Read Before Proceeding!"
' Stop the form from opening
Cancel = True
Else
' All clear, continue with form opening
' Patient ID was selected on main form

' Run Security Code
LAS_EnableSecurity Me

' Maximize the form
DoCmd.Maximize

' Apply a filter to match chosen Patient Number and set
DoCmd.ApplyFilter , "[Patient Number] = " & _
[Forms]![Command and Control Center]![SelectPatient]

' Fill in Protocol ID value
Me.Protocol_ID.DefaultValue = DLookup("ProtocolID",
"tblDefaults")

' Fill in Protocol Title
Me.Protocol_Title.DefaultValue = """" & _
DLookup("ProtocolTitle", "tblDefaults") & """"
End If
End If

ExitPoint:
Exit Sub

Error_Handler:
If Err.Number = 2467 Then
' Ignore
Else
' Unexpected Error
MsgBox "An unanticipated error has occurred." & _
"The error number is " & Err.Number & _
" and the description is '" & Err.description & "'" & _
" Please contact your System Administrator."
End If
Resume ExitPoint

End Sub



And let me confirm.. this error is occurring only when your form
has
no
records in it?

THIS OCCURS WHETHER OR NOT THE FORM HAS RECORDS IN IT.

HTH

-ted


--

Ken Snell
<MS ACCESS MVP>


hi ken,

using my best copy and paste strategies, the code i'm using (and
i'll
tell
you in one shake of a lamb's tail how it's failing) is as under
(with a
breakpoint on 'pn')

Private Sub Add_Record_DblClick(Cancel As Integer)
On Error GoTo Err_Add_Record_DblClick
Dim sql As String
Dim pn As Long
Dim mn As Integer

pn = [Forms]![Command and Control Center]![SelectPatient]
mn = Nz(DMax("[Med Number]", "[Concomitant Medications]",
"[Patient
Number] = " _
& [Forms]![Command and Control Center]![SelectPatient]), 0) + 1

sql = "INSERT INTO [Concomitant Medications] ([Patient Number],
[MedNumber])" & _
"SELECT '" & pn & "', '" & mn & "';"

ds.Execute sql, dbFailOnError


Dim db As Database
Set db = CurrentDb
db.Execute sql

Set db = Nothing

Me.Requery

Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
rs.FindFirst "[Patient Number]='" & pn & "' and [Med Number] =
'" &
mn
&
"'"

If rs.NoMatch Then
MsgBox "something's wrong"

Else
Me.Bookmark = rs.Bookmark
End If

Exit_Add_Record_DblClick:
Set rs = Nothing
Exit Sub

Err_Add_Record_DblClick:
MsgBox Err.Number & " = " & Err.description
Resume Exit_Add_Record_DblClick

End Sub

so as i "F8" my way, i find the same "424 = Object required"
error's
showing
itself :-(

-ted

:

You didn't change to Me.RecordsetClone in your code; you're
still
using
Me.Recordset.Clone.

Also, your INSERT INTO string is going to fail when you try to
execute
it
because you're not delimiting the string values with '
characters
when
you
build the SQL string.

Similarly, the FindFirst step will fail without ' characters.


Try this modified code:
-----------------------

Private Sub Add_Record_DblClick(Cancel As Integer)
On Error GoTo Err_Add_Record_DblClick
Dim sql As String
Dim pn As Long
Dim mn As Integer

pn = [Forms]![Command and Control Center]![SelectPatient]
mn = Nz(DMax("[Med Number]", "[Concomitant Medications]",
"[Patient
Number] = " _
& [Forms]![Command and Control Center]![SelectPatient]), 0) +
1

sql = "INSERT INTO [Concomitant Medications] ([Patient
Number],
[Med
Number])" & _
"SELECT '" & pn & "', '" & mn & "';"

ds.Execute sql, dbFailOnError


Dim db As Database
Set db = CurrentDb
db.Execute sql

Set db = Nothing

Me.Requery

Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
rs.FindFirst "[Patient Number]='" & pn & "' and [Med Number] =
'"
&
mn
&
"'"

If rs.NoMatch Then
MsgBox "something's wrong"

Else
Me.Bookmark = rs.Bookmark
End If

Exit_Add_Record_DblClick:
Set rs = Nothing
Exit Sub

Err_Add_Record_DblClick:
MsgBox Err.Number & " = " & Err.description
Resume Exit_Add_Record_DblClick

End Sub


--

Ken Snell
<MS ACCESS MVP>

hi ken,

using the vba (below) it matters not whether i use one or the
other,
it's
now giving me a "424 = Object required" error message. i put a
breakpoint
on
the 'pn = ' statement and i "F8"ed my way down the code where
i
see
it
jump
to the statement which displays the said 424 msg :-(

Private Sub Add_Record_DblClick(Cancel As Integer)
On Error GoTo Err_Add_Record_DblClick
Dim sql As String
Dim pn As Long
Dim mn As Integer

pn = [Forms]![Command and Control Center]![SelectPatient]
mn = Nz(DMax("[Med Number]", "[Concomitant Medications]",
"[Patient
Number] = " _
& [Forms]![Command and Control Center]![SelectPatient]), 0) +
1

sql = "INSERT INTO [Concomitant Medications] ([Patient
Number],
[Med
Number])" & _
"SELECT " & CStr(pn) & " AS PN, " & CStr(mn) & " AS MN;"

ds.Execute sql, dbFailOnError


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 [Med
Number]
=
" &
CStr(mn)

If rs.NoMatch Then
MsgBox "something's wrong"
End If

Me.Bookmark = rs.Bookmark

Exit_Add_Record_DblClick:
Exit Sub

Err_Add_Record_DblClick:
MsgBox Err.Number & " = " & Err.description
Resume Exit_Add_Record_DblClick

End Sub

-ted



:

Use Me.RecordsetClone recordset, not Me.Recordset.Clone
recordset.

--

Ken Snell
<MS ACCESS MVP>

so, ken....where's all this leave yours truly?

-ted


:

Hmmmm.... but the Help files say that the bookmarks are
compatible:

"Use the Clone method to create multiple, duplicate
Recordset
objects.
Each
Recordset can have its own current record. Using Clone by
itself
doesn't
change the data in the objects or in their underlying
structures.
When
you
use the Clone method, you can share bookmarks between two
or
more
Recordset
objects because their bookmarks are interchangeable."

I then tried the setup using two separate clone recordsets
of
the
form's
recordset. When trying to set one of the clone's bookmark
to
the
bookmark
of
the other clone, I still get the Type Mismatch error.

So the Help files appear to be incorrect for this use of
Clone
method
of
a
form's recordset.

--

Ken Snell
<MS ACCESS MVP>


in
message
In my test, I get a Type Mismatch error when trying to
set
the
form's
Bookmark (Me.Bookmark) to the recordset's bookmark
(rst.Bookmark)
when
rst
is the Recordset.Clone.

Marsh correctly points out that you should be using
RecordsetClone,
not
Recordset.Clone, in your code.
 
M

Marshall Barton

Ted, the devil is in the details. "Essentially the same"
can be miles apart in some cases and must be coded and
debugged separately.

I have been unable to track this thread as closely as Ken
(who is providing some excellent advice on how to post
effective questions), and you should pay close attention to
his ideas and requests for additional information. Except
for analyzing it in detail, don't let the other situation
get in the way of clear thinking about this problem(s?).
--
Marsh
MVP [MS Access]


i will remove the single apostrophes. but what's REALLLLLLY puzzling is that
essentially the same code 'but for' a substitution of "Command and Control
Center", Med Number, and "Concomitant Medications" for their counterparts in
it WORKS!
what's so all importantly unusual about what i'm trying to do with
"Concomitant Medications" or the environment surrounding it that's resulting
in all the 'hooplah"?

Ted said:
using my best copy and paste strategies, the code i'm using (and i'll tell
you in one shake of a lamb's tail how it's failing) is as under (with a
breakpoint on 'pn')
[]
sql = "INSERT INTO [Concomitant Medications] ([Patient Number],
[MedNumber])" & _
"SELECT '" & pn & "', '" & mn & "';"
Marshall Barton said:
Another point. I see you removed the CStr functions, but
you added extra quotes inplace of it. The quotes should
cause a type mismatch error, since you said the two fields
are numeric.

"SELECT " & pn & ", " & mn

and the same issue in the FindFirst:

rs.FindFirst "[Patient Number]=" & pn & " and [Med
Number]=" & mn
 
G

Guest

you're quite right marsh and i think because of it i'm 'seeing' the problem a
bit more clearly and hopefully/possibly the solution as well. i submit my
latest evolution of the vba code for you (both of you) below. i have assigned
(Dim-med) prt to protocol title and pid to protocol id and used parts of the
vba code which appears in my onopen event property to the task of solving for
them. i have added the two fields into my insert and select statements
statements so that the sequence is consisten with the appearance of the
fields in the underlying table.

Private Sub Add_Record_DblClick(Cancel As Integer)
On Error GoTo Err_Add_Record_DblClick
Dim sql As String
Dim pn As Long
Dim mn As Integer
Dim db As Database
Dim pid As Long
Dim prt As String

Dim rs As DAO.Recordset

Set db = CurrentDb
pn = [Forms]![Command and Control Center]![SelectPatient]
mn = Nz(DMax("[Med Number]", "[Concomitant Medications]", "[Patient
Number] = " _
& [Forms]![Command and Control Center]![SelectPatient]), 0) + 1
pid = DLookup("ProtocolID", "tblDefaults")
prt = DLookup("ProtocolTitle", "tblDefaults")

sql = "INSERT INTO [Concomitant Medications] ([Protocol ID],[Protocol
Title],[Patient Number], [Med Number])" & _
"SELECT " & pid & " , " & prt & " , " & pn & " , " & mn & " ;"


db.Execute sql, dbFailOnError

Me.Requery

Set rs = Me.RecordsetClone
rs.FindFirst "[Patient Number]= " & pn & " and [Med Number] = " & mn & " "

If rs.NoMatch Then
MsgBox "something's wrong"

Else
Me.Bookmark = rs.Bookmark
End If

Exit_Add_Record_DblClick:
Set rs = Nothing
Set db = Nothing
Exit Sub

Err_Add_Record_DblClick:
MsgBox Err.Number & " = " & Err.description
Resume Exit_Add_Record_DblClick

End Sub

there is a however, however! i.e.

"3075 = Syntax error (missing operator) in query expression 'Phase II Study
of OSI-774 (Erlotinib, Tarceva) in Elderly Patients'."

this longwinded text being the contents of the Protocol Title.

am i getting warm?

what's up with 3075?

-ted


Marshall Barton said:
Ted, the devil is in the details. "Essentially the same"
can be miles apart in some cases and must be coded and
debugged separately.

I have been unable to track this thread as closely as Ken
(who is providing some excellent advice on how to post
effective questions), and you should pay close attention to
his ideas and requests for additional information. Except
for analyzing it in detail, don't let the other situation
get in the way of clear thinking about this problem(s?).
--
Marsh
MVP [MS Access]


i will remove the single apostrophes. but what's REALLLLLLY puzzling is that
essentially the same code 'but for' a substitution of "Command and Control
Center", Med Number, and "Concomitant Medications" for their counterparts in
it WORKS!
what's so all importantly unusual about what i'm trying to do with
"Concomitant Medications" or the environment surrounding it that's resulting
in all the 'hooplah"?

Ted wrote:
using my best copy and paste strategies, the code i'm using (and i'll tell
you in one shake of a lamb's tail how it's failing) is as under (with a
breakpoint on 'pn')
[]
sql = "INSERT INTO [Concomitant Medications] ([Patient Number],
[MedNumber])" & _
"SELECT '" & pn & "', '" & mn & "';"
Marshall Barton said:
Another point. I see you removed the CStr functions, but
you added extra quotes inplace of it. The quotes should
cause a type mismatch error, since you said the two fields
are numeric.

"SELECT " & pn & ", " & mn

and the same issue in the FindFirst:

rs.FindFirst "[Patient Number]=" & pn & " and [Med
Number]=" & mn
 
G

Guest

marsh/ken:

i just thought i'd add a "MsgBox sql" line in my vba and it displayed the
contents of the INSERT INTO text. looking at it, i have this gut impression i
know what the problem is. my instinct is is that there's an innocent comma
(",") in the title which is confounding things. am i getting warmer? if i'm
not off base w/ my hunch, how would we tell vba to ignore this comma?

-ted


Marshall Barton said:
Ted, the devil is in the details. "Essentially the same"
can be miles apart in some cases and must be coded and
debugged separately.

I have been unable to track this thread as closely as Ken
(who is providing some excellent advice on how to post
effective questions), and you should pay close attention to
his ideas and requests for additional information. Except
for analyzing it in detail, don't let the other situation
get in the way of clear thinking about this problem(s?).
--
Marsh
MVP [MS Access]


i will remove the single apostrophes. but what's REALLLLLLY puzzling is that
essentially the same code 'but for' a substitution of "Command and Control
Center", Med Number, and "Concomitant Medications" for their counterparts in
it WORKS!
what's so all importantly unusual about what i'm trying to do with
"Concomitant Medications" or the environment surrounding it that's resulting
in all the 'hooplah"?

Ted wrote:
using my best copy and paste strategies, the code i'm using (and i'll tell
you in one shake of a lamb's tail how it's failing) is as under (with a
breakpoint on 'pn')
[]
sql = "INSERT INTO [Concomitant Medications] ([Patient Number],
[MedNumber])" & _
"SELECT '" & pn & "', '" & mn & "';"
Marshall Barton said:
Another point. I see you removed the CStr functions, but
you added extra quotes inplace of it. The quotes should
cause a type mismatch error, since you said the two fields
are numeric.

"SELECT " & pn & ", " & mn

and the same issue in the FindFirst:

rs.FindFirst "[Patient Number]=" & pn & " and [Med
Number]=" & mn
 
M

Marshall Barton

Ted said:
i just thought i'd add a "MsgBox sql" line in my vba and it displayed the
contents of the INSERT INTO text. looking at it, i have this gut impression i
know what the problem is. my instinct is is that there's an innocent comma
(",") in the title which is confounding things. am i getting warmer? if i'm
not off base w/ my hunch, how would we tell vba to ignore this comma?


Excellent idea wrt to using a MsgBox. I think you
definitely spotted something important there, but you are
misinterpreting the correction. The title is a Text type
field, so this one requires quotes around it (unlike the
nemeric fields).
 
G

Guest

hi marsh,

can you give me the syntax. what would it look like for the prt variable?
something like yadeyadee ", " & "prt" & " , " yadeyadee....? or is it one
of those 'goofy' instances where you need to have doublequotes nested within
other doublequotes or something like that? one thing, i don't want the text
to appear with quotations around it in the actual table. hope that can be
avoided.

thanks for the msgbox kudos btw!

-ted
 
M

Marshall Barton

It's one of those "goofy" instances. Actually, the
situation is very common since its the right way to deal
with text fields.

yadeyadee & ", """ & prt & """ , " & yadeyadee

or alternatively, as you had it inappropriately for the
numeric values before:

yadeyadee & ", '" & prt & "' , " & yadeyadee

but the latter is more likely to fail if the prt value
contains an apostophe.
 
G

Guest

marsh (and ken), this seems to be doing it :)

as usual, seeing a little success starts me thinking and when that happens
it can get 'dangerous'....i added a few more fields that i thought could be
'defaulted' but when i came to a binary list field ("Continuing") on my form
("Yes";"No") which is coded on the form/table as having "No" be its default
things got 'interesting'. the error i get when i add it (using the code i'm
pasting immediately below) reads:

91 = Object variable of With block variable not set


in my Dim statements this is the 'cnt' field i dimmed as "Listbox". is that
my doing or in the nature of list fields and their relation to SQL commands?

Private Sub Add_Record_DblClick(Cancel As Integer)
On Error GoTo Err_Add_Record_DblClick

Dim sql As String
Dim pn As Long
Dim mn As Integer
Dim db As Database
Dim pid As Long
Dim prt As String
Dim unt As String
Dim PRN As String
Dim med As String
Dim cnt As ListBox

Dim rs As DAO.Recordset

Set db = CurrentDb
pn = [Forms]![Command and Control Center]![SelectPatient]
mn = Nz(DMax("[Med Number]", "[Concomitant Medications]", "[Patient
Number] = " _
& [Forms]![Command and Control Center]![SelectPatient]), 0) + 1
pid = DLookup("ProtocolID", "tblDefaults")
prt = DLookup("ProtocolTitle", "tblDefaults")
unt = "mg"
PRN = "No"
med = "At baseline"
cnt = "No"

sql = "INSERT INTO [Concomitant Medications] ([Protocol ID],[Protocol
Title],[Patient Number],[Med Number],[Unit],[PRN],[Medication
Taken],[Continuing])" & _
"SELECT " & pid & " , """ & prt & """ , " & pn & " , " & mn & " , """
& unt & """ , """ & PRN & """ , """ & med & """ ,""" & cnt & """ ;"

MsgBox sql

db.Execute sql, dbFailOnError

Me.Requery

Set rs = Me.RecordsetClone
rs.FindFirst "[Patient Number]= " & pn & " and [Med Number] = " & mn & " "

If rs.NoMatch Then
MsgBox "something's wrong"

Else
Me.Bookmark = rs.Bookmark
End If

Exit_Add_Record_DblClick:
Set rs = Nothing
Set db = Nothing
Exit Sub

Err_Add_Record_DblClick:
MsgBox Err.Number & " = " & Err.description
Resume Exit_Add_Record_DblClick

End Sub


Marshall Barton said:
It's one of those "goofy" instances. Actually, the
situation is very common since its the right way to deal
with text fields.

yadeyadee & ", """ & prt & """ , " & yadeyadee

or alternatively, as you had it inappropriately for the
numeric values before:

yadeyadee & ", '" & prt & "' , " & yadeyadee

but the latter is more likely to fail if the prt value
contains an apostophe.
--
Marsh
MVP [MS Access]

can you give me the syntax. what would it look like for the prt variable?
something like yadeyadee ", " & "prt" & " , " yadeyadee....? or is it one
of those 'goofy' instances where you need to have doublequotes nested within
other doublequotes or something like that? one thing, i don't want the text
to appear with quotations around it in the actual table. hope that can be
avoided.
 
M

Marshall Barton

Ted, you really need to be more careful about copying one
set of code to another situation. As I've said numerous
times, the "extra" quotes around a field value only applies
to TEXT type field. You are adding them for a Yes/No
field. A Yes/No field has values of True or False, which is
actuall stored as -1 or 0. A Yes/No field does NOT contain
the text string "Yes" or "No", which is only a display
format. Double check the field types in the table and make
sure that you only use the "extra" quotes for TEXT and Memo
fields.

As for the Dim cnt As ListBox, this declares cnt to be a
list box object, not a string or a number. The name implies
that the VALUE of the list box is probably a number, so it
should be either Integer or Long, depending on the number's
magnitude.
--
Marsh
MVP [MS Access]

marsh (and ken), this seems to be doing it :)

as usual, seeing a little success starts me thinking and when that happens
it can get 'dangerous'....i added a few more fields that i thought could be
'defaulted' but when i came to a binary list field ("Continuing") on my form
("Yes";"No") which is coded on the form/table as having "No" be its default
things got 'interesting'. the error i get when i add it (using the code i'm
pasting immediately below) reads:

91 = Object variable of With block variable not set


in my Dim statements this is the 'cnt' field i dimmed as "Listbox". is that
my doing or in the nature of list fields and their relation to SQL commands?

Private Sub Add_Record_DblClick(Cancel As Integer)
On Error GoTo Err_Add_Record_DblClick

Dim sql As String
Dim pn As Long
Dim mn As Integer
Dim db As Database
Dim pid As Long
Dim prt As String
Dim unt As String
Dim PRN As String
Dim med As String
Dim cnt As ListBox

Dim rs As DAO.Recordset

Set db = CurrentDb
pn = [Forms]![Command and Control Center]![SelectPatient]
mn = Nz(DMax("[Med Number]", "[Concomitant Medications]", "[Patient
Number] = " _
& [Forms]![Command and Control Center]![SelectPatient]), 0) + 1
pid = DLookup("ProtocolID", "tblDefaults")
prt = DLookup("ProtocolTitle", "tblDefaults")
unt = "mg"
PRN = "No"
med = "At baseline"
cnt = "No"

sql = "INSERT INTO [Concomitant Medications] ([Protocol ID],[Protocol
Title],[Patient Number],[Med Number],[Unit],[PRN],[Medication
Taken],[Continuing])" & _
"SELECT " & pid & " , """ & prt & """ , " & pn & " , " & mn & " , """
& unt & """ , """ & PRN & """ , """ & med & """ ,""" & cnt & """ ;"

MsgBox sql

db.Execute sql, dbFailOnError

Me.Requery

Set rs = Me.RecordsetClone
rs.FindFirst "[Patient Number]= " & pn & " and [Med Number] = " & mn & " "

If rs.NoMatch Then
MsgBox "something's wrong"

Else
Me.Bookmark = rs.Bookmark
End If

Exit_Add_Record_DblClick:
Set rs = Nothing
Set db = Nothing
Exit Sub

Err_Add_Record_DblClick:
MsgBox Err.Number & " = " & Err.description
Resume Exit_Add_Record_DblClick

End Sub


Marshall Barton said:
It's one of those "goofy" instances. Actually, the
situation is very common since its the right way to deal
with text fields.

yadeyadee & ", """ & prt & """ , " & yadeyadee

or alternatively, as you had it inappropriately for the
numeric values before:

yadeyadee & ", '" & prt & "' , " & yadeyadee

but the latter is more likely to fail if the prt value
contains an apostophe.
--
Marsh
MVP [MS Access]

can you give me the syntax. what would it look like for the prt variable?
something like yadeyadee ", " & "prt" & " , " yadeyadee....? or is it one
of those 'goofy' instances where you need to have doublequotes nested within
other doublequotes or something like that? one thing, i don't want the text
to appear with quotations around it in the actual table. hope that can be
avoided.


Ted wrote:
i just thought i'd add a "MsgBox sql" line in my vba and it displayed the
contents of the INSERT INTO text. looking at it, i have this gut impression i
know what the problem is. my instinct is is that there's an innocent comma
(",") in the title which is confounding things. am i getting warmer? if i'm
not off base w/ my hunch, how would we tell vba to ignore this comma?


:
Excellent idea wrt to using a MsgBox. I think you
definitely spotted something important there, but you are
misinterpreting the correction. The title is a Text type
field, so this one requires quotes around it (unlike the
nemeric fields).
 
G

Guest

hi marsh, let me mend some fences here....

i guess i'll have to disambiguate my problem description. on reading it, i
can understand how you came to the conclusion you have. what i tried to say
is that i had created an ordinary listbox (capable of having many possible
responses) which (just happened to have) had only two of them -- those being
a "Yes" and a "No". i did not intend to imply that i had created a binary Y/N
field which i think is where when i used the word 'binary' things started to
drift a bit off the page. that being said, i fiddled with the code some more,
and after barking back at me a few times, i finally got it to work. the vba
i'm using is immediately below:

Private Sub Add_Record_DblClick(Cancel As Integer)
On Error GoTo Err_Add_Record_DblClick

Dim sql As String
Dim pn As Long
Dim mn As Integer
Dim db As Database
Dim pid As Long
Dim prt As String
Dim unt As String
Dim PRN As String
Dim med As String
Dim cnt As String ' <--- this refers to my listbox field
Dim upd As String


Dim rs As DAO.Recordset

Set db = CurrentDb
pn = [Forms]![Command and Control Center]![SelectPatient]
mn = Nz(DMax("[Med Number]", "[Concomitant Medications]", "[Patient
Number] = " _
& [Forms]![Command and Control Center]![SelectPatient]), 0) + 1
pid = DLookup("ProtocolID", "tblDefaults")
prt = DLookup("ProtocolTitle", "tblDefaults")
unt = "mg"
PRN = "No"
med = "At baseline"
cnt = "No"
upd = "New record added on " & Date & " at " & Time & " by " &
LAS_GetUserName() & ";"


sql = "INSERT INTO [Concomitant Medications] ([Protocol ID],[Protocol
Title],[Patient Number],[Med Number],[Unit],[PRN],[Medication
Taken],[Continuing],[Updates])" & _
"SELECT " & pid & " , """ & prt & """ , " & pn & " , " & mn & " , """
& unt & """ , """ & PRN & """ , """ & med & """ ,""" & cnt & """ , """ &
upd & """ ;"

' MsgBox sql

db.Execute sql, dbFailOnError

Me.Requery

Set rs = Me.RecordsetClone
rs.FindFirst "[Patient Number]= " & pn & " and [Med Number] = " & mn & " "

If rs.NoMatch Then
MsgBox "something's wrong"

Else
Me.Bookmark = rs.Bookmark
End If

Exit_Add_Record_DblClick:
Set rs = Nothing
Set db = Nothing
Exit Sub

Err_Add_Record_DblClick:
MsgBox Err.Number & " = " & Err.description
Resume Exit_Add_Record_DblClick

End Sub


Marshall Barton said:
Ted, you really need to be more careful about copying one
set of code to another situation. As I've said numerous
times, the "extra" quotes around a field value only applies
to TEXT type field. You are adding them for a Yes/No
field. A Yes/No field has values of True or False, which is
actuall stored as -1 or 0. A Yes/No field does NOT contain
the text string "Yes" or "No", which is only a display
format. Double check the field types in the table and make
sure that you only use the "extra" quotes for TEXT and Memo
fields.

As for the Dim cnt As ListBox, this declares cnt to be a
list box object, not a string or a number. The name implies
that the VALUE of the list box is probably a number, so it
should be either Integer or Long, depending on the number's
magnitude.
--
Marsh
MVP [MS Access]

marsh (and ken), this seems to be doing it :)

as usual, seeing a little success starts me thinking and when that happens
it can get 'dangerous'....i added a few more fields that i thought could be
'defaulted' but when i came to a binary list field ("Continuing") on my form
("Yes";"No") which is coded on the form/table as having "No" be its default
things got 'interesting'. the error i get when i add it (using the code i'm
pasting immediately below) reads:

91 = Object variable of With block variable not set


in my Dim statements this is the 'cnt' field i dimmed as "Listbox". is that
my doing or in the nature of list fields and their relation to SQL commands?

Private Sub Add_Record_DblClick(Cancel As Integer)
On Error GoTo Err_Add_Record_DblClick

Dim sql As String
Dim pn As Long
Dim mn As Integer
Dim db As Database
Dim pid As Long
Dim prt As String
Dim unt As String
Dim PRN As String
Dim med As String
Dim cnt As ListBox

Dim rs As DAO.Recordset

Set db = CurrentDb
pn = [Forms]![Command and Control Center]![SelectPatient]
mn = Nz(DMax("[Med Number]", "[Concomitant Medications]", "[Patient
Number] = " _
& [Forms]![Command and Control Center]![SelectPatient]), 0) + 1
pid = DLookup("ProtocolID", "tblDefaults")
prt = DLookup("ProtocolTitle", "tblDefaults")
unt = "mg"
PRN = "No"
med = "At baseline"
cnt = "No"

sql = "INSERT INTO [Concomitant Medications] ([Protocol ID],[Protocol
Title],[Patient Number],[Med Number],[Unit],[PRN],[Medication
Taken],[Continuing])" & _
"SELECT " & pid & " , """ & prt & """ , " & pn & " , " & mn & " , """
& unt & """ , """ & PRN & """ , """ & med & """ ,""" & cnt & """ ;"

MsgBox sql

db.Execute sql, dbFailOnError

Me.Requery

Set rs = Me.RecordsetClone
rs.FindFirst "[Patient Number]= " & pn & " and [Med Number] = " & mn & " "

If rs.NoMatch Then
MsgBox "something's wrong"

Else
Me.Bookmark = rs.Bookmark
End If

Exit_Add_Record_DblClick:
Set rs = Nothing
Set db = Nothing
Exit Sub

Err_Add_Record_DblClick:
MsgBox Err.Number & " = " & Err.description
Resume Exit_Add_Record_DblClick

End Sub


Marshall Barton said:
It's one of those "goofy" instances. Actually, the
situation is very common since its the right way to deal
with text fields.

yadeyadee & ", """ & prt & """ , " & yadeyadee

or alternatively, as you had it inappropriately for the
numeric values before:

yadeyadee & ", '" & prt & "' , " & yadeyadee

but the latter is more likely to fail if the prt value
contains an apostophe.
--
Marsh
MVP [MS Access]


Ted wrote:
can you give me the syntax. what would it look like for the prt variable?
something like yadeyadee ", " & "prt" & " , " yadeyadee....? or is it one
of those 'goofy' instances where you need to have doublequotes nested within
other doublequotes or something like that? one thing, i don't want the text
to appear with quotations around it in the actual table. hope that can be
avoided.


Ted wrote:
i just thought i'd add a "MsgBox sql" line in my vba and it displayed the
contents of the INSERT INTO text. looking at it, i have this gut impression i
know what the problem is. my instinct is is that there's an innocent comma
(",") in the title which is confounding things. am i getting warmer? if i'm
not off base w/ my hunch, how would we tell vba to ignore this comma?


:
Excellent idea wrt to using a MsgBox. I think you
definitely spotted something important there, but you are
misinterpreting the correction. The title is a Text type
field, so this one requires quotes around it (unlike the
nemeric fields).
 
M

Marshall Barton

Some more of that devilry in the details ;-)

At least we were on the right track and I'm happy to hear
that you've worked it out.
--
Marsh
MVP [MS Access]


hi marsh, let me mend some fences here....

i guess i'll have to disambiguate my problem description. on reading it, i
can understand how you came to the conclusion you have. what i tried to say
is that i had created an ordinary listbox (capable of having many possible
responses) which (just happened to have) had only two of them -- those being
a "Yes" and a "No". i did not intend to imply that i had created a binary Y/N
field which i think is where when i used the word 'binary' things started to
drift a bit off the page. that being said, i fiddled with the code some more,
and after barking back at me a few times, i finally got it to work. the vba
i'm using is immediately below:

Private Sub Add_Record_DblClick(Cancel As Integer)
On Error GoTo Err_Add_Record_DblClick

Dim sql As String
Dim pn As Long
Dim mn As Integer
Dim db As Database
Dim pid As Long
Dim prt As String
Dim unt As String
Dim PRN As String
Dim med As String
Dim cnt As String ' <--- this refers to my listbox field
Dim upd As String


Dim rs As DAO.Recordset

Set db = CurrentDb
pn = [Forms]![Command and Control Center]![SelectPatient]
mn = Nz(DMax("[Med Number]", "[Concomitant Medications]", "[Patient
Number] = " _
& [Forms]![Command and Control Center]![SelectPatient]), 0) + 1
pid = DLookup("ProtocolID", "tblDefaults")
prt = DLookup("ProtocolTitle", "tblDefaults")
unt = "mg"
PRN = "No"
med = "At baseline"
cnt = "No"
upd = "New record added on " & Date & " at " & Time & " by " &
LAS_GetUserName() & ";"


sql = "INSERT INTO [Concomitant Medications] ([Protocol ID],[Protocol
Title],[Patient Number],[Med Number],[Unit],[PRN],[Medication
Taken],[Continuing],[Updates])" & _
"SELECT " & pid & " , """ & prt & """ , " & pn & " , " & mn & " , """
& unt & """ , """ & PRN & """ , """ & med & """ ,""" & cnt & """ , """ &
upd & """ ;"

' MsgBox sql

db.Execute sql, dbFailOnError

Me.Requery

Set rs = Me.RecordsetClone
rs.FindFirst "[Patient Number]= " & pn & " and [Med Number] = " & mn & " "

If rs.NoMatch Then
MsgBox "something's wrong"

Else
Me.Bookmark = rs.Bookmark
End If

Exit_Add_Record_DblClick:
Set rs = Nothing
Set db = Nothing
Exit Sub

Err_Add_Record_DblClick:
MsgBox Err.Number & " = " & Err.description
Resume Exit_Add_Record_DblClick

End Sub


Marshall Barton said:
Ted, you really need to be more careful about copying one
set of code to another situation. As I've said numerous
times, the "extra" quotes around a field value only applies
to TEXT type field. You are adding them for a Yes/No
field. A Yes/No field has values of True or False, which is
actuall stored as -1 or 0. A Yes/No field does NOT contain
the text string "Yes" or "No", which is only a display
format. Double check the field types in the table and make
sure that you only use the "extra" quotes for TEXT and Memo
fields.

As for the Dim cnt As ListBox, this declares cnt to be a
list box object, not a string or a number. The name implies
that the VALUE of the list box is probably a number, so it
should be either Integer or Long, depending on the number's
magnitude.
--
Marsh
MVP [MS Access]

marsh (and ken), this seems to be doing it :)

as usual, seeing a little success starts me thinking and when that happens
it can get 'dangerous'....i added a few more fields that i thought could be
'defaulted' but when i came to a binary list field ("Continuing") on my form
("Yes";"No") which is coded on the form/table as having "No" be its default
things got 'interesting'. the error i get when i add it (using the code i'm
pasting immediately below) reads:

91 = Object variable of With block variable not set


in my Dim statements this is the 'cnt' field i dimmed as "Listbox". is that
my doing or in the nature of list fields and their relation to SQL commands?

Private Sub Add_Record_DblClick(Cancel As Integer)
On Error GoTo Err_Add_Record_DblClick

Dim sql As String
Dim pn As Long
Dim mn As Integer
Dim db As Database
Dim pid As Long
Dim prt As String
Dim unt As String
Dim PRN As String
Dim med As String
Dim cnt As ListBox

Dim rs As DAO.Recordset

Set db = CurrentDb
pn = [Forms]![Command and Control Center]![SelectPatient]
mn = Nz(DMax("[Med Number]", "[Concomitant Medications]", "[Patient
Number] = " _
& [Forms]![Command and Control Center]![SelectPatient]), 0) + 1
pid = DLookup("ProtocolID", "tblDefaults")
prt = DLookup("ProtocolTitle", "tblDefaults")
unt = "mg"
PRN = "No"
med = "At baseline"
cnt = "No"

sql = "INSERT INTO [Concomitant Medications] ([Protocol ID],[Protocol
Title],[Patient Number],[Med Number],[Unit],[PRN],[Medication
Taken],[Continuing])" & _
"SELECT " & pid & " , """ & prt & """ , " & pn & " , " & mn & " , """
& unt & """ , """ & PRN & """ , """ & med & """ ,""" & cnt & """ ;"

MsgBox sql

db.Execute sql, dbFailOnError

Me.Requery

Set rs = Me.RecordsetClone
rs.FindFirst "[Patient Number]= " & pn & " and [Med Number] = " & mn & " "

If rs.NoMatch Then
MsgBox "something's wrong"

Else
Me.Bookmark = rs.Bookmark
End If

Exit_Add_Record_DblClick:
Set rs = Nothing
Set db = Nothing
Exit Sub

Err_Add_Record_DblClick:
MsgBox Err.Number & " = " & Err.description
Resume Exit_Add_Record_DblClick

End Sub


:

It's one of those "goofy" instances. Actually, the
situation is very common since its the right way to deal
with text fields.

yadeyadee & ", """ & prt & """ , " & yadeyadee

or alternatively, as you had it inappropriately for the
numeric values before:

yadeyadee & ", '" & prt & "' , " & yadeyadee

but the latter is more likely to fail if the prt value
contains an apostophe.
--
Marsh
MVP [MS Access]


Ted wrote:
can you give me the syntax. what would it look like for the prt variable?
something like yadeyadee ", " & "prt" & " , " yadeyadee....? or is it one
of those 'goofy' instances where you need to have doublequotes nested within
other doublequotes or something like that? one thing, i don't want the text
to appear with quotations around it in the actual table. hope that can be
avoided.


Ted wrote:
i just thought i'd add a "MsgBox sql" line in my vba and it displayed the
contents of the INSERT INTO text. looking at it, i have this gut impression i
know what the problem is. my instinct is is that there's an innocent comma
(",") in the title which is confounding things. am i getting warmer? if i'm
not off base w/ my hunch, how would we tell vba to ignore this comma?


:
Excellent idea wrt to using a MsgBox. I think you
definitely spotted something important there, but you are
misinterpreting the correction. The title is a Text type
field, so this one requires quotes around it (unlike the
nemeric fields).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top