I have a procedure which whips through a recordset and selects the email addresses of employees according to certain conditions, blah blah blah, that is all fine and dandy.
At the moment, if the email address isn't stored then the procedure just doesn't add it. What I would like to do is make a list of the records that don't get their email address added due to the fact they're missing, and then display this to the user somehow.
I thought I could use an array to store the names of the employees although never having used arrays in VBA I 've used them in other languages and assumed it'd be similar.
I tried setting the dimension of the array to the .recordcount but got an error message saying constant expression required so I gave up on that approach.
Then I thought I could set the dimensions to be just
(1 To 1,1 To 2)
and then increase the dimensions everytime something is added in the manner of
(1 To 2,1 To 2)
(1 To 3,1 To 2)
(1 To 4,1 To 2)
etc etc using the Redim statement.
but now I get a subscript out of range error(number 9 error no less!Anyone know what number 1 is?) on the Redim statement line and I can't see why.
I'm now beginning to wonder whether I need an Array at all and haven't yet even thought how I'm going to display all this data to the user.
Sooooooooooo, anyone know why this is happening? The code's below:
Dim notSet(),i as integer
Set db = CurrentDb
Set qdf = db.QueryDefs("qryMassEmail"
i = 1
'Set the three parameters in the query.
qdf![Forms!frmMassEmail!CCode] = Forms![frmMassEmail]![CCode]
qdf![Forms!frmMassEmail!CoDate] = Nz(Forms![frmMassEmail]![CoDate], "*"
qdf![Forms!frmMassEmail!Status] = Nz(Forms![frmMassEmail]![Status], "*"
Set rs = qdf.OpenRecordset()
With rs
Do While Not rs.EOF
'If this is the first email address...
If Len(sText) = 0 Then
'...If an Email Address does exist and it's not equal to "Not Set"...
If Len(![EMail Address]) And Not (![EMail Address] = "Not Set"
Then
'...add the first address to the string.
sText = ![EMail Address]
Else
ReDim Preserve notSet(1 to i,1 to 2)
notSet(i, 1) = ![Forename]
notSet(i, 2) = ![Surname]
i = i + 1
End If
'Otherwise this is not the first email address to be added.
Else
If Len(![EMail Address]) And Not (![EMail Address] = "Not Set"
Then
'Add the new address on to the end of the sText.
sText = sText & "; " & ![EMail Address]
Else
ReDim Preserve notSet(1 to i,1 to 2)
notSet(i, 1) = ![Forename]
notSet(i, 2) = ![Surname]
i = i + 1
End If
End If
'Move to the next record in the recordset.
.MoveNext
Loop
End With
Cheers for any help,
Pete
At the moment, if the email address isn't stored then the procedure just doesn't add it. What I would like to do is make a list of the records that don't get their email address added due to the fact they're missing, and then display this to the user somehow.
I thought I could use an array to store the names of the employees although never having used arrays in VBA I 've used them in other languages and assumed it'd be similar.
I tried setting the dimension of the array to the .recordcount but got an error message saying constant expression required so I gave up on that approach.
Then I thought I could set the dimensions to be just
(1 To 1,1 To 2)
and then increase the dimensions everytime something is added in the manner of
(1 To 2,1 To 2)
(1 To 3,1 To 2)
(1 To 4,1 To 2)
etc etc using the Redim statement.
but now I get a subscript out of range error(number 9 error no less!Anyone know what number 1 is?) on the Redim statement line and I can't see why.
I'm now beginning to wonder whether I need an Array at all and haven't yet even thought how I'm going to display all this data to the user.
Sooooooooooo, anyone know why this is happening? The code's below:
Dim notSet(),i as integer
Set db = CurrentDb
Set qdf = db.QueryDefs("qryMassEmail"
i = 1
'Set the three parameters in the query.
qdf![Forms!frmMassEmail!CCode] = Forms![frmMassEmail]![CCode]
qdf![Forms!frmMassEmail!CoDate] = Nz(Forms![frmMassEmail]![CoDate], "*"
qdf![Forms!frmMassEmail!Status] = Nz(Forms![frmMassEmail]![Status], "*"
Set rs = qdf.OpenRecordset()
With rs
Do While Not rs.EOF
'If this is the first email address...
If Len(sText) = 0 Then
'...If an Email Address does exist and it's not equal to "Not Set"...
If Len(![EMail Address]) And Not (![EMail Address] = "Not Set"
'...add the first address to the string.
sText = ![EMail Address]
Else
ReDim Preserve notSet(1 to i,1 to 2)
notSet(i, 1) = ![Forename]
notSet(i, 2) = ![Surname]
i = i + 1
End If
'Otherwise this is not the first email address to be added.
Else
If Len(![EMail Address]) And Not (![EMail Address] = "Not Set"
'Add the new address on to the end of the sText.
sText = sText & "; " & ![EMail Address]
Else
ReDim Preserve notSet(1 to i,1 to 2)
notSet(i, 1) = ![Forename]
notSet(i, 2) = ![Surname]
i = i + 1
End If
End If
'Move to the next record in the recordset.
.MoveNext
Loop
End With
Cheers for any help,
Pete