> > The below program works for everything except the update. I am trying to
> > make the program apply to various tables and fields.
[quoted text clipped - 58 lines]
> and Select Case. Most people consider that the only acceptable use of GoTo
> in VBA is in error handling.
> Thanks Brian!! Apparantly my question should have been how to create the
> alias or pointer so that I could change the field name once in the program
[quoted text clipped - 12 lines]
> Thanks for your help.
> Jerry
OK, I see what you are trying to do. Let us suppose, then, that you had the
name of the field in a variable called, say, arg3, in much the same way that
you have the name of the table in arg2. You already have the value in arg1,
so the assignment you want to perform, before the rstb01.Update, would look
like this:
rstb01(arg3) = arg1
Regarding the GoTo's, I too am an old COBOL programmer, and I considered
GoTo just as disgusting then. I don't understand at all what you say about
VBA's control-of-flow statements. I, and millions of others, find that they
behave just fine. If you could post a specific problem here, I'm sure
someone could tell you what you are doing wrong. Incidentally, the
control-of-flow statements in VBA are identical to those in VB6.
vtj - 30 Nov 2004 15:45 GMT
Hi Brian,
You wanted an example of VBA not knowing what it is doing. Here it is:
Debug.Print
DoCmd.SetWarnings False
Dim dbb01 As DAO.Database
Dim rstb01 As DAO.Recordset
Set dbb01 = CurrentDb()
Set rstb01 = dbb01.OpenRecordset("test", dbOpenDynaset)
Dim ssn As Variant
rstb01.MoveFirst
If (rstb01.EOF) Then GoTo bo1 Else
Dim var1 As Variant
var1 = [rstb01]![ssn]
GoTo b02
b03:
rstb01.MoveNext
If (rstb01.EOF) Then GoTo bo1 Else
counter = 0
var1 = [rstb01]![ssn]
Debug.Print var1
b02:
rstb01.Edit
If [rstb01]![ssn] = Null Then GoTo b03 'Tried using var1 instead of
[rstb01]![ssn]
'Tried defining(DIM) the items as String
It does not matter what I do VBA will not recognize a "null" field. It
always tells me that it is an improper use of null when all I'm trying to do
is determine if a field is null.
Suggestions????
Jerry
> > Thanks Brian!! Apparantly my question should have been how to create the
> > alias or pointer so that I could change the field name once in the program
[quoted text clipped - 32 lines]
> someone could tell you what you are doing wrong. Incidentally, the
> control-of-flow statements in VBA are identical to those in VB6.
Brian - 30 Nov 2004 16:52 GMT
> Hi Brian,
>
[quoted text clipped - 34 lines]
>
> Jerry
It isn't the expression "[rstb01]![ssn] = Null" that gives an "Invalid use
of null" error. Comparing anything to Null always returns False.
Therefore, the "GoTo b03" branch is never executed, with the result that
whatever code follows is always executed, even if rstb01!ssn is null. So,
if you are then assigning rstb01!ssn to anything other than a variant, you
will indeed get an "Invalid use of Null" error.
This isn't because VBA doesn't know what it's doing, it's because YOU don't
know what you are doing. To test something for null, you need to use the
IsNull function e.g.:
If IsNull(rstb01!ssn) Then...
I repeat, comparing anything to Null ALWAYS returns False, and to test for
Null you use the IsNull function. No inconsistency, no confusion, no need
to bitch at the language: you simply need to learn it properly!
Brian - 30 Nov 2004 17:16 GMT
> Hi Brian,
>
[quoted text clipped - 34 lines]
>
> Jerry
BTW, here is the smart way of implementing your loop:
Dim dbb01 As DAO.Database
Dim rstb01 As DAO.Recordset
Set dbb01 = CurrentDb()
Set rstb01 = dbb01.OpenRecordset("test", dbOpenDynaset)
Do Until rstb01.EOF
If Not IsNull(rstb01!ssn) Then
'Do some stuff here
End If
rstb01.MoveNext
Loop