473,569 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Caption property default value

I want to use the caption property for fields in a recordset as a condition
in a loop. That is, I only want to consider those fields which have
captions:

For each fld in RecordsetName.F ields
If fld.Properties( "Caption") <"" then
do something

The problem is that all fields are included, even those with no caption set.
I've tried IsMissing, IsEmpty and IsNull for the test but none will filter
out those fields without a caption.
What is the default value for captions?
--
Bob Darlington
Brisbane
Dec 11 '06 #1
6 3199
If the property has never been used, you should get error 3270 (Property not
found) when you try to refer to the caption.

Do you have something masking this, Bob?
Perhaps:
On Error Resume Next?

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Bob Darlington" <bo*@dpcmanAX.c om.auwrote in message
news:45******** **************@ news.optusnet.c om.au...
>I want to use the caption property for fields in a recordset as a condition
in a loop. That is, I only want to consider those fields which have
captions:

For each fld in RecordsetName.F ields
If fld.Properties( "Caption") <"" then
do something

The problem is that all fields are included, even those with no caption
set.
I've tried IsMissing, IsEmpty and IsNull for the test but none will filter
out those fields without a caption.
What is the default value for captions?
--
Bob Darlington
Brisbane

Dec 11 '06 #2
Thanks Allen. You got it in one .... again.
So I rewrote the code to the following:
PrintReports first calls the problem function (CreateTenantCh anges) to
create the table on which it is built.

'---------------------------------------------------------------------------------------
' Procedure : PrintReports
' DateTime : 18/11/2006 09:11
' Author : Bob Darlington
' Purpose :
'---------------------------------------------------------------------------------------
'
Public Function PrintReports(vV iew As Byte) As Boolean

10 On Error GoTo PrintReports_Er ror
Dim strRpt As String

20 If Me.Dirty Then DoCmd.RunComman d acCmdSaveRecord

30 If Me!cbSummary Then
40 Call CreateTenantCha nges(Me!TenantC ounter, Me!RefID)
50 strRpt = "rTenantChanges Summary"
60 Else
70 strRpt = "rLVA"
80 End If

90 DoCmd.OpenRepor t strRpt, vView

CloseFunction:
100 On Error Resume Next

110 DoCmd.Hourglass False
120 Exit Function

PrintReports_Er ror:
130 MsgBox "Error " & Err.Number & " (" & Err.Description & ") " _
& "in procedure PrintReports in Line " & Erl & "."
140 Resume CloseFunction
End Function

'---------------------------------------------------------------------------------------
' Procedure : CreateTenantCha nges
' DateTime : 18/11/2006 09:18
' Author : Bob Darlington
' Purpose : Creates tTenantChanges for use in PrintReports and AcceptDraft
'---------------------------------------------------------------------------------------
'
Public Function CreateTenantCha nges(vTenantCou nter As Long, vRefID As Long)
As Boolean
10 On Error GoTo CreateTenantCha nges_Error

Dim db As Database, rsOld As Recordset, rsNew As Recordset,
rsTenantChanges As Recordset
Dim fld As Field
Dim strFld As String, strCaption As String
Dim vEventID As Byte

20 Set db = CurrentDb
30 Set rsOld = db.OpenRecordse t("SELECT * FROM tTenantDetails WHERE
TenantCounter = " & vRefID)
40 Set rsNew = db.OpenRecordse t("SELECT * FROM tTenantDetails WHERE
TenantCounter = " & vTenantCounter)
50 Set rsTenantChanges = db.OpenRecordse t("tTenantChang es")

60 With rsTenantChanges
70 Do Until .EOF
80 .Delete
90 .MoveNext
100 Loop
110 End With

120 With rsOld
130 For Each fld In rsOld.Fields
140 strFld = fld.Name
150 strCaption = fld.Properties( "Caption")

210 If fld.Value <rsNew(strFld). Value Then
220 rsTenantChanges .AddNew
230 rsTenantChanges !ChangeTable = "tTenantDetails "
240 rsTenantChanges !TenantCounter = rsNew!TenantCou nter
250 rsTenantChanges !FieldOldValue = rsOld(strFld).V alue
260 rsTenantChanges !FieldNewValue = rsNew(strFld).V alue
270 rsTenantChanges !FieldCaption = strCaption
290 rsTenantChanges .Update
300 End If
NextField:
310 Next
320 End With

330 CreateTenantCha nges = True

CloseFunction:
340 On Error Resume Next
350 rsOld.Close
360 Set rsOld = Nothing
370 rsNew.Close
380 Set rsNew = Nothing
390 Set db = Nothing
400 DoCmd.Hourglass False
410 Exit Function

CreateTenantCha nges_Error:
420 If Err = 3270 Then 'Caption not assigned
430 GoTo NextField
440 Else
450 MsgBox "Error " & Err.Number & " (" & Err.Description & ") " _
& "in procedure CreateTenantCha nges in Line " & Erl & "."
460 Resume CloseFunction
470 End If
End Function

The first 2 fields are 'TenantID' and 'TenantCounter' (neither of which has
a caption).
When the function reaches line 150 for the first field, it encounters the
error 3270 as expected, and loops to the next field. But when it reaches
line 150 the second time, it exits the function to line 130 (Error Code) in
the calling function (PrintReports) and generates error 3270. I can't see
where or how the error number is transmitted back to the calling function,
or why the error code doesn't trigger in the second loop.
Any ideas?

--
Bob Darlington
Brisbane
"Allen Browne" <Al*********@Se eSig.invalidwro te in message
news:45******** **************@ per-qv1-newsreader-01.iinet.net.au ...
If the property has never been used, you should get error 3270 (Property
not found) when you try to refer to the caption.

Do you have something masking this, Bob?
Perhaps:
On Error Resume Next?

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Bob Darlington" <bo*@dpcmanAX.c om.auwrote in message
news:45******** **************@ news.optusnet.c om.au...
>>I want to use the caption property for fields in a recordset as a
condition in a loop. That is, I only want to consider those fields which
have captions:

For each fld in RecordsetName.F ields
If fld.Properties( "Caption") <"" then
do something

The problem is that all fields are included, even those with no caption
set.
I've tried IsMissing, IsEmpty and IsNull for the test but none will
filter out those fields without a caption.
What is the default value for captions?
--
Bob Darlington
Brisbane


Dec 11 '06 #3
In cases where I expect an error could occur, my personal preference is to
break that line out to a separate procedure to handle the error rather than
jump aound in a routine, trying to guess or debug which line generated the
error. (I presume those line numbers are just for debugging, as they really
slow the execution down.)

Using the examples below, you can avoid the error in your main procedure
with:
If HasProperty(fld , "Caption") Then
'go ahead and refer to the caption
Else
'skip it.
End If

Alternatively, if you want to set the value of the property, creating it if
it doesn't exist, use:
Call SetPropertyDAO( fld, "Caption", dbText, "This is my caption")

Public Function HasProperty(obj As Object, strPropName As String) As Boolean
'Purpose: Return true if the object has the property.
Dim vardummy As Variant

On Error Resume Next
vardummy = obj.Properties( strPropName)
HasProperty = (Err.Number = 0)
End Function

Function SetPropertyDAO( obj As Object, strPropertyName As String, intType As
Integer, varValue As Variant, Optional strErrMsg As String) As Boolean
On Error GoTo ErrHandler
'Purpose: Set a property for an object, creating if necessary.
'Arguments: obj = the object whose property should be set.
' strPropertyName = the name of the property to set.
' intType = the type of property (needed for creating)
' varValue = the value to set this property to.
' strErrMsg = string to append any error message to.

If HasProperty(obj , strPropertyName ) Then
obj.Properties( strPropertyName ) = varValue
Else
obj.Properties. Append obj.CreatePrope rty(strProperty Name, intType,
varValue)
End If
SetPropertyDAO = True

ExitHandler:
Exit Function

ErrHandler:
strErrMsg = strErrMsg & obj.Name & "." & strPropertyName & " not set to
" & varValue & ". Error " & Err.Number & " - " & Err.Description & vbCrLf
Resume ExitHandler
End Function

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Bob Darlington" <bo*@dpcmanAX.c om.auwrote in message
news:45******** *************** @news.optusnet. com.au...
Thanks Allen. You got it in one .... again.
So I rewrote the code to the following:
PrintReports first calls the problem function (CreateTenantCh anges) to
create the table on which it is built.

'---------------------------------------------------------------------------------------
' Procedure : PrintReports
' DateTime : 18/11/2006 09:11
' Author : Bob Darlington
' Purpose :
'---------------------------------------------------------------------------------------
'
Public Function PrintReports(vV iew As Byte) As Boolean

10 On Error GoTo PrintReports_Er ror
Dim strRpt As String

20 If Me.Dirty Then DoCmd.RunComman d acCmdSaveRecord

30 If Me!cbSummary Then
40 Call CreateTenantCha nges(Me!TenantC ounter, Me!RefID)
50 strRpt = "rTenantChanges Summary"
60 Else
70 strRpt = "rLVA"
80 End If

90 DoCmd.OpenRepor t strRpt, vView

CloseFunction:
100 On Error Resume Next

110 DoCmd.Hourglass False
120 Exit Function

PrintReports_Er ror:
130 MsgBox "Error " & Err.Number & " (" & Err.Description & ") " _
& "in procedure PrintReports in Line " & Erl & "."
140 Resume CloseFunction
End Function

'---------------------------------------------------------------------------------------
' Procedure : CreateTenantCha nges
' DateTime : 18/11/2006 09:18
' Author : Bob Darlington
' Purpose : Creates tTenantChanges for use in PrintReports and
AcceptDraft
'---------------------------------------------------------------------------------------
'
Public Function CreateTenantCha nges(vTenantCou nter As Long, vRefID As
Long) As Boolean
10 On Error GoTo CreateTenantCha nges_Error

Dim db As Database, rsOld As Recordset, rsNew As Recordset,
rsTenantChanges As Recordset
Dim fld As Field
Dim strFld As String, strCaption As String
Dim vEventID As Byte

20 Set db = CurrentDb
30 Set rsOld = db.OpenRecordse t("SELECT * FROM tTenantDetails WHERE
TenantCounter = " & vRefID)
40 Set rsNew = db.OpenRecordse t("SELECT * FROM tTenantDetails WHERE
TenantCounter = " & vTenantCounter)
50 Set rsTenantChanges = db.OpenRecordse t("tTenantChang es")

60 With rsTenantChanges
70 Do Until .EOF
80 .Delete
90 .MoveNext
100 Loop
110 End With

120 With rsOld
130 For Each fld In rsOld.Fields
140 strFld = fld.Name
150 strCaption = fld.Properties( "Caption")

210 If fld.Value <rsNew(strFld). Value Then
220 rsTenantChanges .AddNew
230 rsTenantChanges !ChangeTable = "tTenantDetails "
240 rsTenantChanges !TenantCounter = rsNew!TenantCou nter
250 rsTenantChanges !FieldOldValue = rsOld(strFld).V alue
260 rsTenantChanges !FieldNewValue = rsNew(strFld).V alue
270 rsTenantChanges !FieldCaption = strCaption
290 rsTenantChanges .Update
300 End If
NextField:
310 Next
320 End With

330 CreateTenantCha nges = True

CloseFunction:
340 On Error Resume Next
350 rsOld.Close
360 Set rsOld = Nothing
370 rsNew.Close
380 Set rsNew = Nothing
390 Set db = Nothing
400 DoCmd.Hourglass False
410 Exit Function

CreateTenantCha nges_Error:
420 If Err = 3270 Then 'Caption not assigned
430 GoTo NextField
440 Else
450 MsgBox "Error " & Err.Number & " (" & Err.Description & ") " _
& "in procedure CreateTenantCha nges in Line " & Erl & "."
460 Resume CloseFunction
470 End If
End Function

The first 2 fields are 'TenantID' and 'TenantCounter' (neither of which
has a caption).
When the function reaches line 150 for the first field, it encounters the
error 3270 as expected, and loops to the next field. But when it reaches
line 150 the second time, it exits the function to line 130 (Error Code)
in the calling function (PrintReports) and generates error 3270. I can't
see where or how the error number is transmitted back to the calling
function, or why the error code doesn't trigger in the second loop.
Any ideas?

--
Bob Darlington
Brisbane
"Allen Browne" <Al*********@Se eSig.invalidwro te in message
news:45******** **************@ per-qv1-newsreader-01.iinet.net.au ...
>If the property has never been used, you should get error 3270 (Property
not found) when you try to refer to the caption.

Do you have something masking this, Bob?
Perhaps:
On Error Resume Next?

"Bob Darlington" <bo*@dpcmanAX.c om.auwrote in message
news:45******* *************** @news.optusnet. com.au...
>>>I want to use the caption property for fields in a recordset as a
condition in a loop. That is, I only want to consider those fields which
have captions:

For each fld in RecordsetName.F ields
If fld.Properties( "Caption") <"" then
do something

The problem is that all fields are included, even those with no caption
set.
I've tried IsMissing, IsEmpty and IsNull for the test but none will
filter out those fields without a caption.
What is the default value for captions?

Dec 12 '06 #4
Thanks Allen. That worked fine.
I guess the behaviour of my code was a result of the goto, which I have
often seen discouraged in this ng.
But I still can't see how the 3270 value got passed back to the calling
function, or why the error code failed to trigger at the second attempt.
Anyway, your solution works so thanks again.
--
Bob Darlington
Brisbane
"Allen Browne" <Al*********@Se eSig.invalidwro te in message
news:45******** **************@ per-qv1-newsreader-01.iinet.net.au ...
In cases where I expect an error could occur, my personal preference is to
break that line out to a separate procedure to handle the error rather
than jump aound in a routine, trying to guess or debug which line
generated the error. (I presume those line numbers are just for debugging,
as they really slow the execution down.)

Using the examples below, you can avoid the error in your main procedure
with:
If HasProperty(fld , "Caption") Then
'go ahead and refer to the caption
Else
'skip it.
End If

Alternatively, if you want to set the value of the property, creating it
if it doesn't exist, use:
Call SetPropertyDAO( fld, "Caption", dbText, "This is my caption")

Public Function HasProperty(obj As Object, strPropName As String) As
Boolean
'Purpose: Return true if the object has the property.
Dim vardummy As Variant

On Error Resume Next
vardummy = obj.Properties( strPropName)
HasProperty = (Err.Number = 0)
End Function

Function SetPropertyDAO( obj As Object, strPropertyName As String, intType
As Integer, varValue As Variant, Optional strErrMsg As String) As Boolean
On Error GoTo ErrHandler
'Purpose: Set a property for an object, creating if necessary.
'Arguments: obj = the object whose property should be set.
' strPropertyName = the name of the property to set.
' intType = the type of property (needed for creating)
' varValue = the value to set this property to.
' strErrMsg = string to append any error message to.

If HasProperty(obj , strPropertyName ) Then
obj.Properties( strPropertyName ) = varValue
Else
obj.Properties. Append obj.CreatePrope rty(strProperty Name, intType,
varValue)
End If
SetPropertyDAO = True

ExitHandler:
Exit Function

ErrHandler:
strErrMsg = strErrMsg & obj.Name & "." & strPropertyName & " not set to
" & varValue & ". Error " & Err.Number & " - " & Err.Description & vbCrLf
Resume ExitHandler
End Function

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Bob Darlington" <bo*@dpcmanAX.c om.auwrote in message
news:45******** *************** @news.optusnet. com.au...
>Thanks Allen. You got it in one .... again.
So I rewrote the code to the following:
PrintReports first calls the problem function (CreateTenantCh anges) to
create the table on which it is built.

'---------------------------------------------------------------------------------------
' Procedure : PrintReports
' DateTime : 18/11/2006 09:11
' Author : Bob Darlington
' Purpose :
'---------------------------------------------------------------------------------------
'
Public Function PrintReports(vV iew As Byte) As Boolean

10 On Error GoTo PrintReports_Er ror
Dim strRpt As String

20 If Me.Dirty Then DoCmd.RunComman d acCmdSaveRecord

30 If Me!cbSummary Then
40 Call CreateTenantCha nges(Me!TenantC ounter, Me!RefID)
50 strRpt = "rTenantChanges Summary"
60 Else
70 strRpt = "rLVA"
80 End If

90 DoCmd.OpenRepor t strRpt, vView

CloseFunctio n:
100 On Error Resume Next

110 DoCmd.Hourglass False
120 Exit Function

PrintReports_E rror:
130 MsgBox "Error " & Err.Number & " (" & Err.Description & ") " _
& "in procedure PrintReports in Line " & Erl & "."
140 Resume CloseFunction
End Function

'---------------------------------------------------------------------------------------
' Procedure : CreateTenantCha nges
' DateTime : 18/11/2006 09:18
' Author : Bob Darlington
' Purpose : Creates tTenantChanges for use in PrintReports and
AcceptDraft
'---------------------------------------------------------------------------------------
'
Public Function CreateTenantCha nges(vTenantCou nter As Long, vRefID As
Long) As Boolean
10 On Error GoTo CreateTenantCha nges_Error

Dim db As Database, rsOld As Recordset, rsNew As Recordset,
rsTenantChange s As Recordset
Dim fld As Field
Dim strFld As String, strCaption As String
Dim vEventID As Byte

20 Set db = CurrentDb
30 Set rsOld = db.OpenRecordse t("SELECT * FROM tTenantDetails WHERE
TenantCounte r = " & vRefID)
40 Set rsNew = db.OpenRecordse t("SELECT * FROM tTenantDetails WHERE
TenantCounte r = " & vTenantCounter)
50 Set rsTenantChanges = db.OpenRecordse t("tTenantChang es")

60 With rsTenantChanges
70 Do Until .EOF
80 .Delete
90 .MoveNext
100 Loop
110 End With

120 With rsOld
130 For Each fld In rsOld.Fields
140 strFld = fld.Name
150 strCaption = fld.Properties( "Caption")

210 If fld.Value <rsNew(strFld). Value Then
220 rsTenantChanges .AddNew
230 rsTenantChanges !ChangeTable = "tTenantDetails "
240 rsTenantChanges !TenantCounter = rsNew!TenantCou nter
250 rsTenantChanges !FieldOldValue = rsOld(strFld).V alue
260 rsTenantChanges !FieldNewValue = rsNew(strFld).V alue
270 rsTenantChanges !FieldCaption = strCaption
290 rsTenantChanges .Update
300 End If
NextField:
310 Next
320 End With

330 CreateTenantCha nges = True

CloseFunctio n:
340 On Error Resume Next
350 rsOld.Close
360 Set rsOld = Nothing
370 rsNew.Close
380 Set rsNew = Nothing
390 Set db = Nothing
400 DoCmd.Hourglass False
410 Exit Function

CreateTenantCh anges_Error:
420 If Err = 3270 Then 'Caption not assigned
430 GoTo NextField
440 Else
450 MsgBox "Error " & Err.Number & " (" & Err.Description & ") " _
& "in procedure CreateTenantCha nges in Line " & Erl & "."
460 Resume CloseFunction
470 End If
End Function

The first 2 fields are 'TenantID' and 'TenantCounter' (neither of which
has a caption).
When the function reaches line 150 for the first field, it encounters the
error 3270 as expected, and loops to the next field. But when it reaches
line 150 the second time, it exits the function to line 130 (Error Code)
in the calling function (PrintReports) and generates error 3270. I can't
see where or how the error number is transmitted back to the calling
function, or why the error code doesn't trigger in the second loop.
Any ideas?

--
Bob Darlington
Brisbane
"Allen Browne" <Al*********@Se eSig.invalidwro te in message
news:45******* *************** @per-qv1-newsreader-01.iinet.net.au ...
>>If the property has never been used, you should get error 3270 (Property
not found) when you try to refer to the caption.

Do you have something masking this, Bob?
Perhaps:
On Error Resume Next?

"Bob Darlington" <bo*@dpcmanAX.c om.auwrote in message
news:45****** *************** *@news.optusnet .com.au...
I want to use the caption property for fields in a recordset as a
condition in a loop. That is, I only want to consider those fields which
have captions:

For each fld in RecordsetName.F ields
If fld.Properties( "Caption") <"" then
do something

The problem is that all fields are included, even those with no caption
set.
I've tried IsMissing, IsEmpty and IsNull for the test but none will
filter out those fields without a caption.
What is the default value for captions?


Dec 12 '06 #5
Perhaps you needed a Resume instead of a Goto after the error:

CreateTenantCha nges_Error:
420 If Err = 3270 Then 'Caption not assigned
430 Resume NextField
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Bob Darlington" <bo*@dpcmanAX.c om.auwrote in message
news:45******** *************** @news.optusnet. com.au...
Thanks Allen. You got it in one .... again.
So I rewrote the code to the following:
PrintReports first calls the problem function (CreateTenantCh anges) to
create the table on which it is built.

'---------------------------------------------------------------------------------------
' Procedure : PrintReports
' DateTime : 18/11/2006 09:11
' Author : Bob Darlington
' Purpose :
'---------------------------------------------------------------------------------------
'
Public Function PrintReports(vV iew As Byte) As Boolean

10 On Error GoTo PrintReports_Er ror
Dim strRpt As String

20 If Me.Dirty Then DoCmd.RunComman d acCmdSaveRecord

30 If Me!cbSummary Then
40 Call CreateTenantCha nges(Me!TenantC ounter, Me!RefID)
50 strRpt = "rTenantChanges Summary"
60 Else
70 strRpt = "rLVA"
80 End If

90 DoCmd.OpenRepor t strRpt, vView

CloseFunction:
100 On Error Resume Next

110 DoCmd.Hourglass False
120 Exit Function

PrintReports_Er ror:
130 MsgBox "Error " & Err.Number & " (" & Err.Description & ") " _
& "in procedure PrintReports in Line " & Erl & "."
140 Resume CloseFunction
End Function

'---------------------------------------------------------------------------------------
' Procedure : CreateTenantCha nges
' DateTime : 18/11/2006 09:18
' Author : Bob Darlington
' Purpose : Creates tTenantChanges for use in PrintReports and
AcceptDraft
'---------------------------------------------------------------------------------------
'
Public Function CreateTenantCha nges(vTenantCou nter As Long, vRefID As
Long) As Boolean
10 On Error GoTo CreateTenantCha nges_Error

Dim db As Database, rsOld As Recordset, rsNew As Recordset,
rsTenantChanges As Recordset
Dim fld As Field
Dim strFld As String, strCaption As String
Dim vEventID As Byte

20 Set db = CurrentDb
30 Set rsOld = db.OpenRecordse t("SELECT * FROM tTenantDetails WHERE
TenantCounter = " & vRefID)
40 Set rsNew = db.OpenRecordse t("SELECT * FROM tTenantDetails WHERE
TenantCounter = " & vTenantCounter)
50 Set rsTenantChanges = db.OpenRecordse t("tTenantChang es")

60 With rsTenantChanges
70 Do Until .EOF
80 .Delete
90 .MoveNext
100 Loop
110 End With

120 With rsOld
130 For Each fld In rsOld.Fields
140 strFld = fld.Name
150 strCaption = fld.Properties( "Caption")

210 If fld.Value <rsNew(strFld). Value Then
220 rsTenantChanges .AddNew
230 rsTenantChanges !ChangeTable = "tTenantDetails "
240 rsTenantChanges !TenantCounter = rsNew!TenantCou nter
250 rsTenantChanges !FieldOldValue = rsOld(strFld).V alue
260 rsTenantChanges !FieldNewValue = rsNew(strFld).V alue
270 rsTenantChanges !FieldCaption = strCaption
290 rsTenantChanges .Update
300 End If
NextField:
310 Next
320 End With

330 CreateTenantCha nges = True

CloseFunction:
340 On Error Resume Next
350 rsOld.Close
360 Set rsOld = Nothing
370 rsNew.Close
380 Set rsNew = Nothing
390 Set db = Nothing
400 DoCmd.Hourglass False
410 Exit Function

CreateTenantCha nges_Error:
420 If Err = 3270 Then 'Caption not assigned
430 GoTo NextField
440 Else
450 MsgBox "Error " & Err.Number & " (" & Err.Description & ") " _
& "in procedure CreateTenantCha nges in Line " & Erl & "."
460 Resume CloseFunction
470 End If
End Function

The first 2 fields are 'TenantID' and 'TenantCounter' (neither of which
has a caption).
When the function reaches line 150 for the first field, it encounters the
error 3270 as expected, and loops to the next field. But when it reaches
line 150 the second time, it exits the function to line 130 (Error Code)
in the calling function (PrintReports) and generates error 3270. I can't
see where or how the error number is transmitted back to the calling
function, or why the error code doesn't trigger in the second loop.
Any ideas?

--
Bob Darlington
Brisbane
"Allen Browne" <Al*********@Se eSig.invalidwro te in message
news:45******** **************@ per-qv1-newsreader-01.iinet.net.au ...
>If the property has never been used, you should get error 3270 (Property
not found) when you try to refer to the caption.

Do you have something masking this, Bob?
Perhaps:
On Error Resume Next?

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Bob Darlington" <bo*@dpcmanAX.c om.auwrote in message
news:45******* *************** @news.optusnet. com.au...
>>>I want to use the caption property for fields in a recordset as a
condition in a loop. That is, I only want to consider those fields which
have captions:

For each fld in RecordsetName.F ields
If fld.Properties( "Caption") <"" then
do something

The problem is that all fields are included, even those with no caption
set.
I've tried IsMissing, IsEmpty and IsNull for the test but none will
filter out those fields without a caption.
What is the default value for captions?
--
Bob Darlington
Brisbane



Dec 12 '06 #6
Thanks Allen.

--
Bob Darlington
Brisbane
"Allen Browne" <Al*********@Se eSig.invalidwro te in message
news:45******** **************@ per-qv1-newsreader-01.iinet.net.au ...
Perhaps you needed a Resume instead of a Goto after the error:

CreateTenantCha nges_Error:
420 If Err = 3270 Then 'Caption not assigned
430 Resume NextField
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Bob Darlington" <bo*@dpcmanAX.c om.auwrote in message
news:45******** *************** @news.optusnet. com.au...
>Thanks Allen. You got it in one .... again.
So I rewrote the code to the following:
PrintReports first calls the problem function (CreateTenantCh anges) to
create the table on which it is built.

'---------------------------------------------------------------------------------------
' Procedure : PrintReports
' DateTime : 18/11/2006 09:11
' Author : Bob Darlington
' Purpose :
'---------------------------------------------------------------------------------------
'
Public Function PrintReports(vV iew As Byte) As Boolean

10 On Error GoTo PrintReports_Er ror
Dim strRpt As String

20 If Me.Dirty Then DoCmd.RunComman d acCmdSaveRecord

30 If Me!cbSummary Then
40 Call CreateTenantCha nges(Me!TenantC ounter, Me!RefID)
50 strRpt = "rTenantChanges Summary"
60 Else
70 strRpt = "rLVA"
80 End If

90 DoCmd.OpenRepor t strRpt, vView

CloseFunctio n:
100 On Error Resume Next

110 DoCmd.Hourglass False
120 Exit Function

PrintReports_E rror:
130 MsgBox "Error " & Err.Number & " (" & Err.Description & ") " _
& "in procedure PrintReports in Line " & Erl & "."
140 Resume CloseFunction
End Function

'---------------------------------------------------------------------------------------
' Procedure : CreateTenantCha nges
' DateTime : 18/11/2006 09:18
' Author : Bob Darlington
' Purpose : Creates tTenantChanges for use in PrintReports and
AcceptDraft
'---------------------------------------------------------------------------------------
'
Public Function CreateTenantCha nges(vTenantCou nter As Long, vRefID As
Long) As Boolean
10 On Error GoTo CreateTenantCha nges_Error

Dim db As Database, rsOld As Recordset, rsNew As Recordset,
rsTenantChange s As Recordset
Dim fld As Field
Dim strFld As String, strCaption As String
Dim vEventID As Byte

20 Set db = CurrentDb
30 Set rsOld = db.OpenRecordse t("SELECT * FROM tTenantDetails WHERE
TenantCounte r = " & vRefID)
40 Set rsNew = db.OpenRecordse t("SELECT * FROM tTenantDetails WHERE
TenantCounte r = " & vTenantCounter)
50 Set rsTenantChanges = db.OpenRecordse t("tTenantChang es")

60 With rsTenantChanges
70 Do Until .EOF
80 .Delete
90 .MoveNext
100 Loop
110 End With

120 With rsOld
130 For Each fld In rsOld.Fields
140 strFld = fld.Name
150 strCaption = fld.Properties( "Caption")

210 If fld.Value <rsNew(strFld). Value Then
220 rsTenantChanges .AddNew
230 rsTenantChanges !ChangeTable = "tTenantDetails "
240 rsTenantChanges !TenantCounter = rsNew!TenantCou nter
250 rsTenantChanges !FieldOldValue = rsOld(strFld).V alue
260 rsTenantChanges !FieldNewValue = rsNew(strFld).V alue
270 rsTenantChanges !FieldCaption = strCaption
290 rsTenantChanges .Update
300 End If
NextField:
310 Next
320 End With

330 CreateTenantCha nges = True

CloseFunctio n:
340 On Error Resume Next
350 rsOld.Close
360 Set rsOld = Nothing
370 rsNew.Close
380 Set rsNew = Nothing
390 Set db = Nothing
400 DoCmd.Hourglass False
410 Exit Function

CreateTenantCh anges_Error:
420 If Err = 3270 Then 'Caption not assigned
430 GoTo NextField
440 Else
450 MsgBox "Error " & Err.Number & " (" & Err.Description & ") " _
& "in procedure CreateTenantCha nges in Line " & Erl & "."
460 Resume CloseFunction
470 End If
End Function

The first 2 fields are 'TenantID' and 'TenantCounter' (neither of which
has a caption).
When the function reaches line 150 for the first field, it encounters the
error 3270 as expected, and loops to the next field. But when it reaches
line 150 the second time, it exits the function to line 130 (Error Code)
in the calling function (PrintReports) and generates error 3270. I can't
see where or how the error number is transmitted back to the calling
function, or why the error code doesn't trigger in the second loop.
Any ideas?

--
Bob Darlington
Brisbane
"Allen Browne" <Al*********@Se eSig.invalidwro te in message
news:45******* *************** @per-qv1-newsreader-01.iinet.net.au ...
>>If the property has never been used, you should get error 3270 (Property
not found) when you try to refer to the caption.

Do you have something masking this, Bob?
Perhaps:
On Error Resume Next?

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Bob Darlington" <bo*@dpcmanAX.c om.auwrote in message
news:45****** *************** *@news.optusnet .com.au...
I want to use the caption property for fields in a recordset as a
condition in a loop. That is, I only want to consider those fields which
have captions:

For each fld in RecordsetName.F ields
If fld.Properties( "Caption") <"" then
do something

The problem is that all fields are included, even those with no caption
set.
I've tried IsMissing, IsEmpty and IsNull for the test but none will
filter out those fields without a caption.
What is the default value for captions?
--
Bob Darlington
Brisbane



Dec 12 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
3770
by: Randall Sell | last post by:
Can anyone confirm if I am being an idiot, or is this a bug in the CSS implementation of Netscape 7.x/Mozilla 1.4 ... give the following single HTML: <html> <head> <style type="text/css"> <!-- caption {
0
3036
by: Chenghui Li | last post by:
We have a problem with the Windows XP theme: We have a IDE which allows other developers to develop visual programs for their customers. Our IDE allow them to set font for window captions easyly (through a dialog). It works fine fo W98, 2000, NT, and XP is the theme is Classic. But on XP if the theme is "Windows XP", the we have a problem: if...
1
2869
by: S. van Beek | last post by:
Dear reader, I can change the caption content of a field in a Form with the following VBA code: Rst!<FieldName>.Caption = "<NewCaptionContent>" But if I do the same in a Table the following error message pops up:
6
8151
by: Richard | last post by:
Hi, I have posted this question on another site but had no luck so far. Sorry about multiposting to those who have seen it. I wish to add the field captions programmatically to the fields properties when I am creating the database (VB5 DAO3.6) but caption does not appear on the properties list. I'm sure it must be posible, and probable...
1
1465
by: Karl | last post by:
Can you update the caption property for fields in a database using code?
1
6900
by: Simon | last post by:
Dear reader, I am familiar with the possibility to change the Caption of a field in a form. But is there also a possibility to change the Caption of a field in the table structure it self.
11
4980
by: Chris Beall | last post by:
See http://pages.prodigy.net/chris_beall/Demo/photo%20block%20experiments.html I've ended up with what seems like a rather complex structure for what I thought would be a somewhat simple problem. Even that complex solution works well only in FireFox (haven't tested Safari...). Can anyone come up with a better solution, where 'better'...
1
1956
by: DavidB | last post by:
I want to be able to find the value of the Caption property of a Page in my Tab Control based solely on the Page Index property value. Is this possible? Example... tcBedrock pFred - Page Index = 0 - Caption = "Slob" pWilma - Page Index = 1 - Caption = "Boring" pBarney - Page Index = 2 - Caption = "Simpleton" pBetty - Page Index = 3 -...
4
2718
by: Bob Darlington | last post by:
I'm using the following code to try to change a caption property for a field in a table. Dim dbs As Database, fld As Field, fFormat As Property Set dbs = OpenDatabase(CurrentDataFile) Set fld = dbs.TableDefs(tblName).Fields(fldName) Set fFormat = fld.CreateProperty("Caption", dbText, strCaption) fld.Properties.Append fFormat Each time...
0
7697
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8120
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7672
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7968
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.