Desparately seeking coding help

M

mlmo300

How do I turn this generally logical statement into SQL code that ca
serve as the record source for a subform control?

IF: (All records WHERE Logsubform![Dtshtnmbr] = Current record’
Logsubform![Dtshtnmbr]) = 1

THEN: Logsubform![Start Time]=Logsubform.Logentry![Begin Time]


IF: (All records WHERE Logsubform![Dtshtnmbr] = Current record’
Logsubform![Dtshtnmbr]) > 1

THEN: Logsubform![Start Time]=(Logsubform![Finish Time] WHER
Logsubform![Actvtynmbr] = Current record’s Logsubform![Actvtynmbr-1]
 
D

Dave Cousineau

Dim SQL As String
Dim R As Recordset

SQL = "SELECT Count(*) As Tally " & _
"FROM MyTable " & _
"WHERE MyWhereClause;"

Set R = CurrentDb.OpenRecordset(SQL, dbOpenSnapshot)

If IsNull(R!Tally) Or R!Tally = "" then
'0 records
ElseIf R!Tally = 0 Then
'0 records
ElseIf R!Tally = 1 Then
'1 record

'i don't use subforms much, i didn't know you could
access fields from a subform just by !'ing

'If [Start Time] and [Begin Time] are fields, which i
think they are, first you shouldn't use spaces in field
names, it just makes things more complicated

'someone else will probably give you a better way to do
this using subforms, and whatever magic they do, but what
i would do in your case is like so:

SQL = "UPDATE MyTable " & _
"SET [Start Time] = " & MyValue & " " & _
"WHERE ID = " & MyRecordID & ";"

CurrentDb.Execute SQL, dbFailOnError

Else
'more than 1 record
'im not going to finish this, unless you really need me
to
'this should be good enough to get you started, if you
decide to go this way, but as i said, someone else will
have a better way using subform magic.

End If
 

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