function not working correctly

  • Thread starter Thread starter mcnewsxp
  • Start date Start date
M

mcnewsxp

i have a function that returns a boolean value.
the value is getting changed properly within the function, but always
retunrs false to the calling subroutine.
any clues what might cuase this?

tia,
mcnewsxp
 
The most common cause of this problem is not assigning the value back to the
function properly...a typo or something of that nature.



Rob
 
The most common cause of this problem is not assigning the value back to
the function properly...a typo or something of that nature.
i tested that by placing this code in the function:

ValidateForm = boolYes
Debug.Print ValidateForm

ValidateForm is the name of my function.

i fixed it by passing a bool value by reference.

still, this is a weird error...
 
I assume you've assigned something to boolYes somewhere and haven't made any
typos there (just to cover all the bases)? Try posting the entire code (or
at least relevant portions of it), as well as the line that calls it.



Rob
 
this is what i was doing:

If Forms(strTag).rcRecordControlExt.DoubleEntryFlag Then
If Not Forms(strTag).rcRecordControlExt.ValidateForm(strFormName)
Exit Sub
End If
End If


but i modified the function to take a ByRef boolean:

boolYes = True
If Forms(strTag).rcRecordControlExt.DoubleEntryFlag Then
Call Forms(strTag).rcRecordControlExt.ValidateForm(strFormName,
boolYes)
If Not boolYes Then
Exit Sub
End If
End If
 
turns out my modified function isn't working right either.
ByRef should change the value in the calling sub routine but it doesn't.
 
ok, my modified function works.
i was calling it in the prototype with a literal ture instead of a bool
variable.
 
Well, it all looks good as far as I can see. What does ValidateForm look
like?

What's rcRecordControlExt...a subform?



Rob
 
Robert said:
Well, it all looks good as far as I can see. What does ValidateForm look
like?


Public Function ValidateForm(ByVal strCurrentForm As String, ByRef
boolYes As Boolean) As Boolean

Dim rst As New ADODB.Recordset
Dim myCntrl As Control
Dim myField As ADODB.Field
Dim sql As String
Dim strNotValid As String
'Dim boolOk As Boolean
Dim intCurrPatient As Integer 'PatientID currently being viewed.
intCurrPatient = rstRecordSet.Fields(strPatIDfield)

sql = "SELECT * FROM " & strValTableName
sql = sql & " WHERE Patient_ID = " & intCurrPatient
rst.Open sql, CurrentProject.Connection

boolYes = True
strNotValid = ""

For Each myCntrl In Forms(strCurrentForm).Controls
For Each myField In rst.Fields
If myCntrl.Name = myField.Name Then
If myCntrl <> myField Or IsNull(myCntrl) <> IsNull(myField)
Then
strNotValid = strNotValid & myCntrl.Name & " " & myCntrl
& " <> " & myField & vbCrLf
boolYes = False
End If
End If
Next myField
Next myCntrl

rst.Close
Set rst = Nothing

If Not boolYes Then
MsgBox strNotValid, vbCritical, "Errors Found!"
End If

'''''i took this out because i don't need it now.
'ValidateForm = boolYes
'Debug.Print ValidateForm

End Function ' ValidateForm()
What's rcRecordControlExt...a subform?
it's really kind of a wrapper for a control that all of the connected
forms use. by that i mean this app contains an electronic version of a
group of related paper forms. one paper form may have a hundred or
more questions so the questions are divided among several forms. each
form has navigation buttons that allow the user to move the next or
previous form. rcRecordControlExt is the instantiated version of this
control.
 
Well, I've got good news and bad the good news is, you're not going
crazy; the bad news is, there's nothing wrong with your code as far as I can
see. The only odd thing is using your wrapper in the original call to the
function...I'm not sure I understand why you're doing that...why not just
use a global function and call it like this:

If Not ValidateForm(strFormName)...

But either way, I can't see how that would interfere in the function being
properly evaluated. Out of curiosity, since you've left it as a function
anyway, try uncommenting the ValidateForm = boolYes line, returning a value
from the function AND leaving the ByRef parameter in there...I'd be curious
to see if they return different values.



Rob
 
Oh, and one other (unrelated) thing I forgot to mention, is that it's
probably a good idea not to rely on the default property for myCtrl and
myField...i.e., use

If myCntrl.Value <> myField.Value Or IsNull(myCntrl.Value) <>
IsNull(myField.Value)

But again, if the code is assigning the proper value to the variable, then
this obviously isn't the source of your problem.



Rob
 
Robert said:
Well, I've got good news and bad the good news is, you're not going
crazy; the bad news is, there's nothing wrong with your code as far as I can
see. The only odd thing is using your wrapper in the original call to the
function...I'm not sure I understand why you're doing that...why not just
use a global function and call it like this:

If Not ValidateForm(strFormName)...

well i inherited this app so i had to retrofit some methods and
properties.
i would not code access vba this way - but it works.
But either way, I can't see how that would interfere in the function being
properly evaluated. Out of curiosity, since you've left it as a function
anyway, try uncommenting the ValidateForm = boolYes line, returning a value
from the function AND leaving the ByRef parameter in there...I'd be curious
to see if they return different values.

i did that and yes, different values are returned.
 
Back
Top