Re: multiple criteria for finding record

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



No, the other way around...

If rs.AbsolutePosition > -1 Then
'Use the existing record
Else
'Create a new record
End If

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

"LAF" <LAF@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:55A91FE2-EDB1-4CBE-AC13-A88EC3E63B0B@xxxxxxxxxxxxxxxx
> Thanks, Graham. I am somewhat new at development, so could I put your
> response in context? The code would be run from an unbound form in which
> the
> user had entered site, date, and time. The issue is whether a new record
> should be written in MyTable, with an additional autonumbered ID, or
> whether
> further data entry in a related junction table should simply use the
> existing
> ID. I assume that the If-Then portion of the code would be the area in
> which
> a bound data entry form for MyTable could be opened and a new record
> written
> (if necessary) and in which a bound data entry form for MyJunctionTable
> could
> be opened and the appropriate ID value could be set in that field. Is
> this
> the right approach?
>
> Regards,
> LAF
>
> "Graham R Seach" wrote:
>
>> Yes, you can, but I wouldn't advise it. Domain functions such as DLookup
>> are
>> notoriosuly slow, and having 3 of them back-to-back can cause latency
>> problems in large tables.
>>
>> I'd be more inclined to use a single recordset:
>> Dim db As Database
>> Dim rs As DAO.Recordset
>> Dim sSQL As String
>>
>> Set db = CurrentDb
>> sSQL = "SELECT ID FROM MyTable " & _
>> "WHERE site = " & Me.txtSite & _
>> " AND [date] = " & Me!txtDate & _
>> " AND [time] = " & Me!txtTime
>>
>> Set rs = db.OpenRecordset(sSQL, dbOpenSnapshot)
>> If rs.AbsolutePosition > -1 Then
>> 'site, date and time already exist in the table
>> End If
>>
>> rs.Close
>> Set rs = Nothing
>> Set db = Nothing
>>
>> Regards,
>> Graham R Seach
>> Microsoft Access MVP
>> Sydney, Australia
>> ---------------------------
>>
>> "LAF" <LAF@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
>> news:52F90ED8-A298-4CFD-B45E-93915B242F9D@xxxxxxxxxxxxxxxx
>> > Is it possible to use the DLookup function 3 times connected by AND in
>> > the
>> > criteria for running a macro for data entry? The issue, I think, is
>> > that
>> > a
>> > master table with an autonumbered primary key, may be part of overall
>> > data
>> > entry. Say that EventID is an autonumbered field that is related to
>> > unique
>> > combinations of site, date, and time. If one were to enter a new
>> > record
>> > for
>> > the master tables and junction table, would it not be important to
>> > determine
>> > if the site, date, and time were the same as a prevous record. If so,
>> > the
>> > EventID of that previous record should be the EventID of the current
>> > record
>> > being entered. It seems that a macro with the specified condition
>> > would
>> > do
>> > the trick. Thus, is it possible that DLookup could be used for site,
>> > date,
>> > and time in association with macro actions? The user could enter site,
>> > date,
>> > and time on an unbound form with a control to run the macro (or code).
>>
>>
>>


.



Relevant Pages

  • Re: multiple criteria for finding record
    ... Thanks, Graham. ... further data entry in a related junction table should simply use the existing ... It seems that a macro with the specified condition would ... >> and time on an unbound form with a control to run the macro. ...
    (microsoft.public.access.forms)
  • Macro??
    ... I have several columns and rows of data and I wish to move certain cells around in the same row. ... I have made a macro that moves 2 cells to a blank space, move 2 other cells into its cells and the moves the first 2 cells in its place ... The macro in this case would swap n08 william with 3 Graham ... Regards ...
    (microsoft.public.excel.newusers)
  • Re: Access 2003 / Forms / Data Entry
    ... >I find this suggestion quite interesting. ... >> Regards, ... >> Graham R Seach ... >> Sydney, Australia ...
    (microsoft.public.access.formscoding)
  • Re: Selecting A Record From A Listbox
    ... You'll have to show us how you're calling the OpenReport method, ... >> Regards, ... >> Graham R Seach ...
    (microsoft.public.access.formscoding)
  • Re: Calculating Age
    ... Regards, ... Graham R Seach ... Microsoft Access 2003 VBA Programmer's Reference ... >> Microsoft Access MVP ...
    (microsoft.public.access.gettingstarted)