Ok, now we are getting somewhere
What version of access are you using?
You can also use the dao version instead of the ADO version
the it will look like this
dim db as dao.database
dim rs as dao.recordset
set db=currentdb()
set rs= db.openrecordset("subqryReporting")
the rest stays the same.
ok now let's try this...
--
Maurice Ausum
:
I changed the code as suggested but noticed that ProjectID doesn't live in
the tblPeriods. They are linked via child (sub form) and master (main form)
by ProjectID.
On the child (sub form) "subqryReporting", PeriodID and ProjectID are joined
in here from various tables.
My code at the moment is this:
rs.Open "select PeriodID from subqryReporting where ProjectID=" & Me.ProjectID
but the error message I recive is on the next line:
CurrentProject.Connection , adOpenStatic, adLockOptimistic
where XxxxxxXxxxxx.Connection, xxXxxxXxxxxx, xxXxxxXxxxxxxxx (connection bit
is highlighted) and the error box is as follows:
Compile Error: invalid use of property
thanks again Maurice
:
rs.Open "select projectid from tblPeriods where projectid=" & me.projectid
I've placed your tablename in the open statement above. I assume the
fieldnames are correct right? Id field is called ProjectID en field on form
is also called ProjectID.
The commented part does nothing because you stated in your first post that
you wanted to check if it exists so that's what we're doing. In stead of the
commented part you can write your own actions like say a messagebox stating
that the record already exists or save the record, whatever you had in mind
after validating if the record existed yet.
--
Maurice Ausum
:
Thanks Maurice, I have tried to fill in the blanks but am not getting
anywhere fast.
My table is called tblReporting, but the PeriodID comes from a joined table
called tblPeriods.
What do I put in the comnmented parts e.g. 'projectid is found so don't add it
I have tried tweaking this for a few hours with no effect.
:
Maybe this could be one way;
in the before update of the record write the following:
dim rs as new adodb.recordset
rs.Open "select projectid from Your table where projectid=" & me.projectid,
CurrentProject.Connection, adOpenStatic, adLockOptimistic
With rs
if not rs.bof and not rs.eof then
'projectid is found so don't add it
else
'projectid not found add it
end if
.Close
End With
Set rs = Nothing
replace the appropriate fields and fieldnames with your own field and
tablenames and give it a try.
--
Maurice Ausum
:
One main form with two subforms (linked by ProjectID), first subform is for
data entry, the second just allows the user to view what has been saved from
the previous subform.
The subform allows users to report on a month basis by selecting a month in
a combo box [PeriodID]. I would like to add some code in the Befire Update
event that checks the PeriodID for a match before it is saved.
Can someone help me with the code please, I have tried various DLookup
snippets of code from this site, but nothing is working as the code does not
really suit my purpose.
regards