alsoascientist
Registered User.
- Local time
- Today, 19:43
- Joined
- Mar 26, 2012
- Messages
- 39
Hi All,
I've not tried to use a function when building an expression before so please bear with me if I am missing something obvious!
I have the following function which is placed in a query to return a concatenated string depending on which comboboxes are currently visible on the form (the idea being to fire a code on the next record button to check for a duplicate of the entire text string).
I seem to be having two issues with it:
1. The code seems to build twice the data that is needed ie [FIELD1]&[FIELD2]&FIELD3][FIELD1]&[FIELD2]&FIELD3] (no '&' in between the two sets) and I can't figure out why. It doesn't do this when I check it by stepping through (that I can see) but does when it is fired from the query. This I can kind of fix by dividing the text in two (as in the code) but I'm not sure if this may be the root of my issue.
2. The function does not return any data. Again if I step through and copy the information from the immediate window and place it in the query I can get the desired information, however if I allow it to work itself I get nothing!
Any ideas where I should be looking?
I've not tried to use a function when building an expression before so please bear with me if I am missing something obvious!
I have the following function which is placed in a query to return a concatenated string depending on which comboboxes are currently visible on the form (the idea being to fire a code on the next record button to check for a duplicate of the entire text string).
I seem to be having two issues with it:
1. The code seems to build twice the data that is needed ie [FIELD1]&[FIELD2]&FIELD3][FIELD1]&[FIELD2]&FIELD3] (no '&' in between the two sets) and I can't figure out why. It doesn't do this when I check it by stepping through (that I can see) but does when it is fired from the query. This I can kind of fix by dividing the text in two (as in the code) but I'm not sure if this may be the root of my issue.
2. The function does not return any data. Again if I step through and copy the information from the immediate window and place it in the query I can get the desired information, however if I allow it to work itself I get nothing!
Any ideas where I should be looking?
Code:
Public Function DuplicateStrChk()
Dim Ctrl As Control
Dim strDup As String
strDup = ""
For Each Ctrl In Forms![myForm].Controls
If Ctrl.ControlType = acComboBox Then
If Ctrl.Visible = True Then
strDup = strDup & "[" & Ctrl.Name & "]&"
End If
End If
Next
If Right(strDup, 1) = "&" Then
strDup = Left(strDup, Len(strDup) - 1)
strDup = Left(strDup, Len(strDup) / 2)
strDup = strDup
End If
End Function
Last edited: