String Delimiters in Find (Again)

T

Trevor

Despite all the help that has been given me, I am still
having problems with quotes/appostrophes in strings.

These are some the addressIDs that I am having a problem
with

Address_ID Surname Forename
""'D DEEPROSE Rebecca (Two Quotes, an
appostrophe and D)
""'( DAVIS Antony (Two Quotes, an
appostrophe and ()
""'C RIPLEY Jack (Two Quotes, an
appostrophe and C)
""'" DAVIES Matthew (Two Quotes, an
appostrophe and another Quote)

The ones that were giving me problems, but no longer are
(FixQuotes fixed this)
were IDs such as:

""C' (Quote, quote, C, appostrophe)
""^' (Quote, quote, hat, appostrophe)

Note that the appostrophe is the last character.

All IDs start with two quotqtion marks and contain two
other characters.

I cannot use a query to join the IDs because there are IDs
such as ""Cx and ""cx which
represent different addresses (Current and previous
address) in the original database,
but a query will return both addresses for the student. I
have actually used a query
to 'get rid' of definately unwanted addresses to compile
the table tblLocalAddresses.

The case problem is resolved after the find, by using
strComp, and findNext if case
does not match.
But still have the problem of the quotes.

I have noticed the possible 'doom loop' if
FixQuotes returns a duff string although
with the strings that I have it doesn't happen.

My code is listed below, without the actual copy code.

TIA again

Trevor


Sub GetAddressFromSIMS(strListToUse As String)
'Looks down StudentList, gets addressID, looks up
addressID in tblLocalAddresses _
if found pastes address data into StudentList
Dim db As Database
Dim rstStudentList As Recordset
Dim rstAddress As Recordset
Dim strCriteria As String
Dim NoAddress As Long
Dim StringMismatch As Long
Dim AddressesAdded As Long
Dim lngMaxRecords As Long
Dim lngRecordCount As Long
Dim fTryAgain As Boolean
Dim TimeNow

On Error GoTo Err_In_Sub
Set db = DBEngine.Workspaces(0).Databases(0)
Set rstAddress = db.OpenRecordset("tblLocalAddresses",
dbOpenDynaset) '(SIMS)
'strListToUse contains a valid tablename
Set rstStudentList = db.OpenRecordset(strListToUse,
dbOpenDynaset) '(SIMS)

DoCmd.Hourglass True

Do Until rstStudentList.EOF
DoEvents
lngRecordCount = lngRecordCount + 1
Forms!frmsearch!ProgBar = lngRecordCount
DoEvents
strCriteria = "[address_ID]='" & rstStudentList!
ADdress_ID & "'"

TryAgain:
'Findfirst generates a 3077 error if strcriteria is
duff. This is trapped and the string is passed to
FixQuotes and the search tried again
rstAddress.FindFirst strCriteria
If rstAddress.NoMatch Then
'No matching address
NoAddress = NoAddress + 1
If fTryAgain Then
MsgBox "Cannot find an address for this
student." & strCriteria
End If
fTryAgain = False
Else
'An address_ID has been found in the Address table
'strComp is used after the find because the
students address_ID _
is case sensitive in SIMS _
and the same ID is used with different case for a
change of address _
The Access search engine is not case sensitive so
a binary strComp _
has to be dome on all found address_IDs for a
student _
to make the search appear case sensitive
Do Until rstAddress.NoMatch
If StrComp(rstAddress!ADdress_ID,
rstStudentList!ADdress_ID, 0) = 0 Then
'Case check of found address_ID is ok so
copy data
rstStudentList.Edit
'Copy code in here


Exit Do
End If
'Case check is not ok, so find the next
address_ID
rstAddress.FindNext strCriteria
Loop
End If
rstStudentList.MoveNext
Loop


exit_Sub:
DoCmd.Hourglass False
rstStudentList.Close
rstAddress.Close
Set rstStudentList = Nothing
Set rstAddress = Nothing
Set db = Nothing
Exit Sub

Err_In_Sub:
Select Case Err.Number
Case 3077 'This is generated every once in a while
because of the format _
of the SIMS address_ID, which contains quotation
marks and _
appostrophies which the Access search engine does
not like too much. _
As there are only a few of these, the error is
ignored, apart from _
counting the duffIDs, and the next student's
address_ID is checked

strCriteria = "Address_ID = '" & FixQuotes
(rstStudentList!ADdress_ID) & "'"
fTryAgain = True
Resume TryAgain

Case Else
MsgBox Err.Number & " " & Err.Description & " in
routine 'GetAddressFromSIMS'", vbCritical, "Error in Sub"
End Select
Resume exit_Sub
End Sub


Function FixQuotes(strToFix As String) As String
Dim strtemp As String
Dim I As Integer

For I = 1 To Len(strToFix)
If Mid(strToFix, I, 1) = Chr$(39) Then
strtemp = strtemp & Chr$(39)
End If
strtemp = strtemp & Mid(strToFix, I, 1)
Next
FixQuotes = strtemp
End Function
 
R

Ron Weiner

Trevor

To test your problem I created two tables tbllName and tbl Address. Both
Tables Have two fields fk and either name or address. Here are the contents
I used for each table in my test.

tblName fk name
""'D DEEPROSE Rebecca
""'( DAVIS Antony
""'C RIPLEY Jack
""'" DAVIES Matthew
""C' One Don't Work
""^' Two Don't Work
""Cx New Upper C guy


tblAddress fk Address
""'D Address for DEEPROSE Rebecca
""'( Address for DAVIS Antony
""'C Address for RIPLEY Jack
""'" Address for DAVIES Matthew
""C' Address for One Don't Work
""^' Address for Two Don't Work
""Cx Address for New Upper C guy
""cx Old Address for New Upper C guy


I wrote a query to join the two tables using fk

SELECT tblName.name, tblAddress.Address
FROM tblName INNER JOIN tblAddress ON tblName.fk = tblAddress.fk
WHERE StrComp([tblAddress].[fk],[tblName].[fk],0)=0

name Address
DEEPROSE Rebecca Address for DEEPROSE Rebecca
DAVIS Antony Address for DAVIS Antony
RIPLEY Jack Address for RIPLEY Jack
DAVIES Matthew Address for DAVIES Matthew
One Don't Work Address for One Don't Work
Two Don't Work Address for Two Don't Work
New Upper C guy Address for New Upper C guy


Note the Old Address for New Upper C guy is not isnt the results.

Am I missing something? Perhaps I just do not understand what your
requirements are.

Ron W


Trevor said:
Despite all the help that has been given me, I am still
having problems with quotes/appostrophes in strings.

These are some the addressIDs that I am having a problem
with

Address_ID Surname Forename
""'D DEEPROSE Rebecca (Two Quotes, an
appostrophe and D)
""'( DAVIS Antony (Two Quotes, an
appostrophe and ()
""'C RIPLEY Jack (Two Quotes, an
appostrophe and C)
""'" DAVIES Matthew (Two Quotes, an
appostrophe and another Quote)

The ones that were giving me problems, but no longer are
(FixQuotes fixed this)
were IDs such as:

""C' (Quote, quote, C, appostrophe)
""^' (Quote, quote, hat, appostrophe)

Note that the appostrophe is the last character.

All IDs start with two quotqtion marks and contain two
other characters.

I cannot use a query to join the IDs because there are IDs
such as ""Cx and ""cx which
represent different addresses (Current and previous
address) in the original database,
but a query will return both addresses for the student. I
have actually used a query
to 'get rid' of definately unwanted addresses to compile
the table tblLocalAddresses.

The case problem is resolved after the find, by using
strComp, and findNext if case
does not match.
But still have the problem of the quotes.

I have noticed the possible 'doom loop' if
FixQuotes returns a duff string although
with the strings that I have it doesn't happen.

My code is listed below, without the actual copy code.

TIA again

Trevor


Sub GetAddressFromSIMS(strListToUse As String)
'Looks down StudentList, gets addressID, looks up
addressID in tblLocalAddresses _
if found pastes address data into StudentList
Dim db As Database
Dim rstStudentList As Recordset
Dim rstAddress As Recordset
Dim strCriteria As String
Dim NoAddress As Long
Dim StringMismatch As Long
Dim AddressesAdded As Long
Dim lngMaxRecords As Long
Dim lngRecordCount As Long
Dim fTryAgain As Boolean
Dim TimeNow

On Error GoTo Err_In_Sub
Set db = DBEngine.Workspaces(0).Databases(0)
Set rstAddress = db.OpenRecordset("tblLocalAddresses",
dbOpenDynaset) '(SIMS)
'strListToUse contains a valid tablename
Set rstStudentList = db.OpenRecordset(strListToUse,
dbOpenDynaset) '(SIMS)

DoCmd.Hourglass True

Do Until rstStudentList.EOF
DoEvents
lngRecordCount = lngRecordCount + 1
Forms!frmsearch!ProgBar = lngRecordCount
DoEvents
strCriteria = "[address_ID]='" & rstStudentList!
ADdress_ID & "'"

TryAgain:
'Findfirst generates a 3077 error if strcriteria is
duff. This is trapped and the string is passed to
FixQuotes and the search tried again
rstAddress.FindFirst strCriteria
If rstAddress.NoMatch Then
'No matching address
NoAddress = NoAddress + 1
If fTryAgain Then
MsgBox "Cannot find an address for this
student." & strCriteria
End If
fTryAgain = False
Else
'An address_ID has been found in the Address table
'strComp is used after the find because the
students address_ID _
is case sensitive in SIMS _
and the same ID is used with different case for a
change of address _
The Access search engine is not case sensitive so
a binary strComp _
has to be dome on all found address_IDs for a
student _
to make the search appear case sensitive
Do Until rstAddress.NoMatch
If StrComp(rstAddress!ADdress_ID,
rstStudentList!ADdress_ID, 0) = 0 Then
'Case check of found address_ID is ok so
copy data
rstStudentList.Edit
'Copy code in here


Exit Do
End If
'Case check is not ok, so find the next
address_ID
rstAddress.FindNext strCriteria
Loop
End If
rstStudentList.MoveNext
Loop


exit_Sub:
DoCmd.Hourglass False
rstStudentList.Close
rstAddress.Close
Set rstStudentList = Nothing
Set rstAddress = Nothing
Set db = Nothing
Exit Sub

Err_In_Sub:
Select Case Err.Number
Case 3077 'This is generated every once in a while
because of the format _
of the SIMS address_ID, which contains quotation
marks and _
appostrophies which the Access search engine does
not like too much. _
As there are only a few of these, the error is
ignored, apart from _
counting the duffIDs, and the next student's
address_ID is checked

strCriteria = "Address_ID = '" & FixQuotes
(rstStudentList!ADdress_ID) & "'"
fTryAgain = True
Resume TryAgain

Case Else
MsgBox Err.Number & " " & Err.Description & " in
routine 'GetAddressFromSIMS'", vbCritical, "Error in Sub"
End Select
Resume exit_Sub
End Sub


Function FixQuotes(strToFix As String) As String
Dim strtemp As String
Dim I As Integer

For I = 1 To Len(strToFix)
If Mid(strToFix, I, 1) = Chr$(39) Then
strtemp = strtemp & Chr$(39)
End If
strtemp = strtemp & Mid(strToFix, I, 1)
Next
FixQuotes = strtemp
End Function
 
R

Ron Weiner

Sheesh! I did not realize this would be so hard to read when posted. Let me
try again

To test your problem I created two tables tblName and tblAddress. Both
Tables Have two fields fk and either name or address. Here are the contents
I used for each table in my test.

tblName
fk name
==== ===================
""'D DEEPROSE Rebecca
""'( DAVIS Antony
""'C RIPLEY Jack
""'" DAVIES Matthew
""C' One Don't Work
""^' Two Don't Work
""Cx New Upper C guy

tblAddress
fk Address
==== ===================
""'D Address for DEEPROSE Rebecca
""'( Address for DAVIS Antony
""'C Address for RIPLEY Jack
""'" Address for DAVIES Matthew
""C' Address for One Don't Work
""^' Address for Two Don't Work
""Cx Address for New Upper C guy
""cx Old Address for New Upper C guy

I wrote a query to join the two tables using fk

SELECT tblName.name, tblAddress.Address
FROM tblName INNER JOIN tblAddress ON tblName.fk = tblAddress.fk
WHERE StrComp([tblAddress].[fk],[tblName].[fk],0)=0

name Address
=============== =========================
DEEPROSE Rebecca Address for DEEPROSE Rebecca
DAVIS Antony Address for DAVIS Antony
RIPLEY Jack Address for RIPLEY Jack
DAVIES Matthew Address for DAVIES Matthew
One Don't Work Address for One Don't Work
Two Don't Work Address for Two Don't Work
New Upper C guy Address for New Upper C guy


Note the Old Address for New Upper C guy is not in the results.

Am I missing something? Perhaps I just do not understand what your
requirements are.

Ron W


Ron Weiner said:
Trevor

To test your problem I created two tables tbllName and tbl Address. Both
Tables Have two fields fk and either name or address. Here are the contents
I used for each table in my test.

tblName fk name
""'D DEEPROSE Rebecca
""'( DAVIS Antony
""'C RIPLEY Jack
""'" DAVIES Matthew
""C' One Don't Work
""^' Two Don't Work
""Cx New Upper C guy


tblAddress fk Address
""'D Address for DEEPROSE Rebecca
""'( Address for DAVIS Antony
""'C Address for RIPLEY Jack
""'" Address for DAVIES Matthew
""C' Address for One Don't Work
""^' Address for Two Don't Work
""Cx Address for New Upper C guy
""cx Old Address for New Upper C guy


I wrote a query to join the two tables using fk

SELECT tblName.name, tblAddress.Address
FROM tblName INNER JOIN tblAddress ON tblName.fk = tblAddress.fk
WHERE StrComp([tblAddress].[fk],[tblName].[fk],0)=0

name Address
DEEPROSE Rebecca Address for DEEPROSE Rebecca
DAVIS Antony Address for DAVIS Antony
RIPLEY Jack Address for RIPLEY Jack
DAVIES Matthew Address for DAVIES Matthew
One Don't Work Address for One Don't Work
Two Don't Work Address for Two Don't Work
New Upper C guy Address for New Upper C guy


Note the Old Address for New Upper C guy is not isnt the results.

Am I missing something? Perhaps I just do not understand what your
requirements are.

Ron W


Trevor said:
Despite all the help that has been given me, I am still
having problems with quotes/appostrophes in strings.

These are some the addressIDs that I am having a problem
with

Address_ID Surname Forename
""'D DEEPROSE Rebecca (Two Quotes, an
appostrophe and D)
""'( DAVIS Antony (Two Quotes, an
appostrophe and ()
""'C RIPLEY Jack (Two Quotes, an
appostrophe and C)
""'" DAVIES Matthew (Two Quotes, an
appostrophe and another Quote)

The ones that were giving me problems, but no longer are
(FixQuotes fixed this)
were IDs such as:

""C' (Quote, quote, C, appostrophe)
""^' (Quote, quote, hat, appostrophe)

Note that the appostrophe is the last character.

All IDs start with two quotqtion marks and contain two
other characters.

I cannot use a query to join the IDs because there are IDs
such as ""Cx and ""cx which
represent different addresses (Current and previous
address) in the original database,
but a query will return both addresses for the student. I
have actually used a query
to 'get rid' of definately unwanted addresses to compile
the table tblLocalAddresses.

The case problem is resolved after the find, by using
strComp, and findNext if case
does not match.
But still have the problem of the quotes.

I have noticed the possible 'doom loop' if
FixQuotes returns a duff string although
with the strings that I have it doesn't happen.

My code is listed below, without the actual copy code.

TIA again

Trevor


Sub GetAddressFromSIMS(strListToUse As String)
'Looks down StudentList, gets addressID, looks up
addressID in tblLocalAddresses _
if found pastes address data into StudentList
Dim db As Database
Dim rstStudentList As Recordset
Dim rstAddress As Recordset
Dim strCriteria As String
Dim NoAddress As Long
Dim StringMismatch As Long
Dim AddressesAdded As Long
Dim lngMaxRecords As Long
Dim lngRecordCount As Long
Dim fTryAgain As Boolean
Dim TimeNow

On Error GoTo Err_In_Sub
Set db = DBEngine.Workspaces(0).Databases(0)
Set rstAddress = db.OpenRecordset("tblLocalAddresses",
dbOpenDynaset) '(SIMS)
'strListToUse contains a valid tablename
Set rstStudentList = db.OpenRecordset(strListToUse,
dbOpenDynaset) '(SIMS)

DoCmd.Hourglass True

Do Until rstStudentList.EOF
DoEvents
lngRecordCount = lngRecordCount + 1
Forms!frmsearch!ProgBar = lngRecordCount
DoEvents
strCriteria = "[address_ID]='" & rstStudentList!
ADdress_ID & "'"

TryAgain:
'Findfirst generates a 3077 error if strcriteria is
duff. This is trapped and the string is passed to
FixQuotes and the search tried again
rstAddress.FindFirst strCriteria
If rstAddress.NoMatch Then
'No matching address
NoAddress = NoAddress + 1
If fTryAgain Then
MsgBox "Cannot find an address for this
student." & strCriteria
End If
fTryAgain = False
Else
'An address_ID has been found in the Address table
'strComp is used after the find because the
students address_ID _
is case sensitive in SIMS _
and the same ID is used with different case for a
change of address _
The Access search engine is not case sensitive so
a binary strComp _
has to be dome on all found address_IDs for a
student _
to make the search appear case sensitive
Do Until rstAddress.NoMatch
If StrComp(rstAddress!ADdress_ID,
rstStudentList!ADdress_ID, 0) = 0 Then
'Case check of found address_ID is ok so
copy data
rstStudentList.Edit
'Copy code in here


Exit Do
End If
'Case check is not ok, so find the next
address_ID
rstAddress.FindNext strCriteria
Loop
End If
rstStudentList.MoveNext
Loop


exit_Sub:
DoCmd.Hourglass False
rstStudentList.Close
rstAddress.Close
Set rstStudentList = Nothing
Set rstAddress = Nothing
Set db = Nothing
Exit Sub

Err_In_Sub:
Select Case Err.Number
Case 3077 'This is generated every once in a while
because of the format _
of the SIMS address_ID, which contains quotation
marks and _
appostrophies which the Access search engine does
not like too much. _
As there are only a few of these, the error is
ignored, apart from _
counting the duffIDs, and the next student's
address_ID is checked

strCriteria = "Address_ID = '" & FixQuotes
(rstStudentList!ADdress_ID) & "'"
fTryAgain = True
Resume TryAgain

Case Else
MsgBox Err.Number & " " & Err.Description & " in
routine 'GetAddressFromSIMS'", vbCritical, "Error in Sub"
End Select
Resume exit_Sub
End Sub


Function FixQuotes(strToFix As String) As String
Dim strtemp As String
Dim I As Integer

For I = 1 To Len(strToFix)
If Mid(strToFix, I, 1) = Chr$(39) Then
strtemp = strtemp & Chr$(39)
End If
strtemp = strtemp & Mid(strToFix, I, 1)
Next
FixQuotes = strtemp
End Function
 
T

Trevor

Ron,
I really appreciate your hanging on to this one and
shaking it around. It seems from your listing that it will
work for me. I havn't tried it yet, 'cause I wanted to get
the thanks in. Given your tables contents and your query,
it must also work for me. Seems that you have solved both
my probs in one hit. I tried your SQL in your previous
post, but it returned the 'duplicates' e.g. The Old
Address for New Upper C guy WAS in the results 'cause I
didn't have the 'WHERE StrComp([tblAddress].[fk],[tblName].
[fk],0)=0' bit in my query, although I was using in in my
feeble attempt at coding.
You obviously did understand from my ramblings what the
problem was, and hopefully the problem has now gone away.
Thanks again. I'll persevere with the SQL later this
evening, and post the results, but I am convinced that it
will work for me.

Trevor
-----Original Message-----
Sheesh! I did not realize this would be so hard to read when posted. Let me
try again

To test your problem I created two tables tblName and tblAddress. Both
Tables Have two fields fk and either name or address. Here are the contents
I used for each table in my test.

tblName
fk name
==== ===================
""'D DEEPROSE Rebecca
""'( DAVIS Antony
""'C RIPLEY Jack
""'" DAVIES Matthew
""C' One Don't Work
""^' Two Don't Work
""Cx New Upper C guy

tblAddress
fk Address
==== ===================
""'D Address for DEEPROSE Rebecca
""'( Address for DAVIS Antony
""'C Address for RIPLEY Jack
""'" Address for DAVIES Matthew
""C' Address for One Don't Work
""^' Address for Two Don't Work
""Cx Address for New Upper C guy
""cx Old Address for New Upper C guy

I wrote a query to join the two tables using fk

SELECT tblName.name, tblAddress.Address
FROM tblName INNER JOIN tblAddress ON tblName.fk = tblAddress.fk
WHERE StrComp([tblAddress].[fk],[tblName].[fk],0)=0

name Address
=============== =========================
DEEPROSE Rebecca Address for DEEPROSE Rebecca
DAVIS Antony Address for DAVIS Antony
RIPLEY Jack Address for RIPLEY Jack
DAVIES Matthew Address for DAVIES Matthew
One Don't Work Address for One Don't Work
Two Don't Work Address for Two Don't Work
New Upper C guy Address for New Upper C guy


Note the Old Address for New Upper C guy is not in the results.

Am I missing something? Perhaps I just do not understand what your
requirements are.

Ron W


Ron Weiner said:
Trevor

To test your problem I created two tables tbllName and tbl Address. Both
Tables Have two fields fk and either name or address.
Here are the
contents
I used for each table in my test.

tblName fk name
""'D DEEPROSE Rebecca
""'( DAVIS Antony
""'C RIPLEY Jack
""'" DAVIES Matthew
""C' One Don't Work
""^' Two Don't Work
""Cx New Upper C guy


tblAddress fk Address
""'D Address for DEEPROSE Rebecca
""'( Address for DAVIS Antony
""'C Address for RIPLEY Jack
""'" Address for DAVIES Matthew
""C' Address for One Don't Work
""^' Address for Two Don't Work
""Cx Address for New Upper C guy
""cx Old Address for New Upper C guy


I wrote a query to join the two tables using fk

SELECT tblName.name, tblAddress.Address
FROM tblName INNER JOIN tblAddress ON tblName.fk = tblAddress.fk
WHERE StrComp([tblAddress].[fk],[tblName].[fk],0)=0

name Address
DEEPROSE Rebecca Address for DEEPROSE Rebecca
DAVIS Antony Address for DAVIS Antony
RIPLEY Jack Address for RIPLEY Jack
DAVIES Matthew Address for DAVIES Matthew
One Don't Work Address for One Don't Work
Two Don't Work Address for Two Don't Work
New Upper C guy Address for New Upper C guy


Note the Old Address for New Upper C guy is not isnt the results.

Am I missing something? Perhaps I just do not understand what your
requirements are.

Ron W


Despite all the help that has been given me, I am still
having problems with quotes/appostrophes in strings.

These are some the addressIDs that I am having a problem
with

Address_ID Surname Forename
""'D DEEPROSE Rebecca (Two Quotes, an
appostrophe and D)
""'( DAVIS Antony (Two Quotes, an
appostrophe and ()
""'C RIPLEY Jack (Two Quotes, an
appostrophe and C)
""'" DAVIES Matthew (Two Quotes, an
appostrophe and another Quote)

The ones that were giving me problems, but no longer are
(FixQuotes fixed this)
were IDs such as:

""C' (Quote, quote, C, appostrophe)
""^' (Quote, quote, hat, appostrophe)

Note that the appostrophe is the last character.

All IDs start with two quotqtion marks and contain two
other characters.

I cannot use a query to join the IDs because there are IDs
such as ""Cx and ""cx which
represent different addresses (Current and previous
address) in the original database,
but a query will return both addresses for the student. I
have actually used a query
to 'get rid' of definately unwanted addresses to compile
the table tblLocalAddresses.

The case problem is resolved after the find, by using
strComp, and findNext if case
does not match.
But still have the problem of the quotes.

I have noticed the possible 'doom loop' if
FixQuotes returns a duff string although
with the strings that I have it doesn't happen.

My code is listed below, without the actual copy code.

TIA again

Trevor


Sub GetAddressFromSIMS(strListToUse As String)
'Looks down StudentList, gets addressID, looks up
addressID in tblLocalAddresses _
if found pastes address data into StudentList
Dim db As Database
Dim rstStudentList As Recordset
Dim rstAddress As Recordset
Dim strCriteria As String
Dim NoAddress As Long
Dim StringMismatch As Long
Dim AddressesAdded As Long
Dim lngMaxRecords As Long
Dim lngRecordCount As Long
Dim fTryAgain As Boolean
Dim TimeNow

On Error GoTo Err_In_Sub
Set db = DBEngine.Workspaces(0).Databases(0)
Set rstAddress = db.OpenRecordset("tblLocalAddresses",
dbOpenDynaset) '(SIMS)
'strListToUse contains a valid tablename
Set rstStudentList = db.OpenRecordset(strListToUse,
dbOpenDynaset) '(SIMS)

DoCmd.Hourglass True

Do Until rstStudentList.EOF
DoEvents
lngRecordCount = lngRecordCount + 1
Forms!frmsearch!ProgBar = lngRecordCount
DoEvents
strCriteria = "[address_ID]='" & rstStudentList!
ADdress_ID & "'"

TryAgain:
'Findfirst generates a 3077 error if strcriteria is
duff. This is trapped and the string is passed to
FixQuotes and the search tried again
rstAddress.FindFirst strCriteria
If rstAddress.NoMatch Then
'No matching address
NoAddress = NoAddress + 1
If fTryAgain Then
MsgBox "Cannot find an address for this
student." & strCriteria
End If
fTryAgain = False
Else
'An address_ID has been found in the Address table
'strComp is used after the find because the
students address_ID _
is case sensitive in SIMS _
and the same ID is used with different case for a
change of address _
The Access search engine is not case sensitive so
a binary strComp _
has to be dome on all found address_IDs for a
student _
to make the search appear case sensitive
Do Until rstAddress.NoMatch
If StrComp(rstAddress!ADdress_ID,
rstStudentList!ADdress_ID, 0) = 0 Then
'Case check of found address_ID is ok so
copy data
rstStudentList.Edit
'Copy code in here


Exit Do
End If
'Case check is not ok, so find the next
address_ID
rstAddress.FindNext strCriteria
Loop
End If
rstStudentList.MoveNext
Loop


exit_Sub:
DoCmd.Hourglass False
rstStudentList.Close
rstAddress.Close
Set rstStudentList = Nothing
Set rstAddress = Nothing
Set db = Nothing
Exit Sub

Err_In_Sub:
Select Case Err.Number
Case 3077 'This is generated every once in a while
because of the format _
of the SIMS address_ID, which contains quotation
marks and _
appostrophies which the Access search engine does
not like too much. _
As there are only a few of these, the error is
ignored, apart from _
counting the duffIDs, and the next student's
address_ID is checked

strCriteria = "Address_ID = '" & FixQuotes
(rstStudentList!ADdress_ID) & "'"
fTryAgain = True
Resume TryAgain

Case Else
MsgBox Err.Number & " " & Err.Description & " in
routine 'GetAddressFromSIMS'", vbCritical, "Error in Sub"
End Select
Resume exit_Sub
End Sub


Function FixQuotes(strToFix As String) As String
Dim strtemp As String
Dim I As Integer

For I = 1 To Len(strToFix)
If Mid(strToFix, I, 1) = Chr$(39) Then
strtemp = strtemp & Chr$(39)
End If
strtemp = strtemp & Mid(strToFix, I, 1)
Next
FixQuotes = strtemp
End Function


.
 
T

Trevor

Ron,
I tried your SQL on my database and it worked a treat and
does exactly what I wanted, thanks a mill.
The simple ones are always the best. It's good to have
experts on hand when the going gets a bit tough (for us
Armatures). I can let my hair grow back now
as I've been tearing it out for a couple of weeks over
this one.

Thanks again for your perseverence.
Regards
Trevor
 

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