how do I pass either a form name or a recordset to the same procedure

K

Keith G Hicks

I have a public procedure that checks the values of several fields in a
table before the calling routine can do further processign. The procedure
can be called from a couple of places. First it can be called from the form
itself where the fields are bound to the controls on the form. Second it can
be called by another procedure that sets up the same fields in a recordset
(not part of a form).

Here's the idea:

Public Sub subStatus(obj as ???)

If IsNull(obj!Field1) Then
strMissingFields = strMissingFields & vbCrLf & " Field 1"
End If
If IsNull(obj!Field2) Then
strMissingFields = strMissingFields & vbCrLf & " Field 2"
End If
If IsNull(obj!Field3) Then
strMissingFields = strMissingFields & vbCrLf & " Field 3"
End If
 
D

Dirk Goldgar

Keith G Hicks said:
I have a public procedure that checks the values of several fields in
a table before the calling routine can do further processign. The
procedure can be called from a couple of places. First it can be
called from the form itself where the fields are bound to the
controls on the form. Second it can be called by another procedure
that sets up the same fields in a recordset (not part of a form).

Here's the idea:

Public Sub subStatus(obj as ???)

If IsNull(obj!Field1) Then
strMissingFields = strMissingFields & vbCrLf & " Field 1"
End If
If IsNull(obj!Field2) Then
strMissingFields = strMissingFields & vbCrLf & " Field 2"
End If
If IsNull(obj!Field3) Then
strMissingFields = strMissingFields & vbCrLf & " Field 3"
End If
.
.
.
.
and so on ...

End Sub

Obvoiusly sometimes I might pass a recordset and other times the
form. So calling the procedure could look like this:

From somewhere in the form it would be as follows:
Call subStatus(me)

or like this:

From where a recordset is created it would be like this:
Set rsTemp = CurrentDb().OpenRecordset("Select * From Test",
dbOpenSnapshot)
Call subStatus(rsTemp)


Any suggestoins on how to pass eitehr a recordset or a form to the
same procedure?

I tried it by using a recordset always in the procedure and calling
it from the form as follows:
Me.RecordSetClone.BookMark = Me.BookMark
Call subStatus(Me.RecordSetClone)

This works well but it looks at the OLD values not any changed values
in the form (and I do not want to do a Me.Dirty = False here, I can't
update the recordset yet with the new values)

Thanks,

Keith

I haven't tested it, but you might try declaring the Sub like this:

Public Sub subStatus(obj as Object)
 
K

Keith G Hicks

That did it. Thanks :)
The simplest solution is usually the best!

Keith

Keith G Hicks said:
I have a public procedure that checks the values of several fields in
a table before the calling routine can do further processign. The
procedure can be called from a couple of places. First it can be
called from the form itself where the fields are bound to the
controls on the form. Second it can be called by another procedure
that sets up the same fields in a recordset (not part of a form).

Here's the idea:

Public Sub subStatus(obj as ???)

If IsNull(obj!Field1) Then
strMissingFields = strMissingFields & vbCrLf & " Field 1"
End If
If IsNull(obj!Field2) Then
strMissingFields = strMissingFields & vbCrLf & " Field 2"
End If
If IsNull(obj!Field3) Then
strMissingFields = strMissingFields & vbCrLf & " Field 3"
End If
.
.
.
.
and so on ...

End Sub

Obvoiusly sometimes I might pass a recordset and other times the
form. So calling the procedure could look like this:

From somewhere in the form it would be as follows:
Call subStatus(me)

or like this:

From where a recordset is created it would be like this:
Set rsTemp = CurrentDb().OpenRecordset("Select * From Test",
dbOpenSnapshot)
Call subStatus(rsTemp)


Any suggestoins on how to pass eitehr a recordset or a form to the
same procedure?

I tried it by using a recordset always in the procedure and calling
it from the form as follows:
Me.RecordSetClone.BookMark = Me.BookMark
Call subStatus(Me.RecordSetClone)

This works well but it looks at the OLD values not any changed values
in the form (and I do not want to do a Me.Dirty = False here, I can't
update the recordset yet with the new values)

Thanks,

Keith

I haven't tested it, but you might try declaring the Sub like this:

Public Sub subStatus(obj as Object)
 

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