Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I keep getting the following error 1

Status
Not open for further replies.

GSMike

Programmer
Feb 7, 2001
143
US
I keep getting the following error message with the code below:
"Variable not defined"
Code:
===========================================================
Sub ParseDBField()
Dim db As Database, rst As Recordset, tdf As TableDef, x As Integer, y As String
Dim fld As Field
Set db = CurrentDb
Set tdf = db.TableDefs("ControlProperties")
Set fld = tdf.Fields("Tip")
Set rst = tdf.OpenRecordset(dbOpenDynaset)
x = 1
Do Until rst.EOF
    rst.MoveFirst
    If asc_code >= 65 And asc_code <= 90 Or asc_code >= 97 And asc_code <= 122 Then
        y = y &amp; Mid(fld.Value, x, 1)
    Else
        y = y &amp; &quot; &quot;
    End If
Loop
End Sub
============================================================
Function asc_code()
asc_code = Asc(Mid(fld.Value, x, 1))
End Function
The question, is how do I make the variable &quot;fld&quot; pass from my sub routine to my function and back again? At least, I think that's why I'm getting this error message.
Thank you for your help.
 
You need to pass both &quot;fld&quot; and &quot;x&quot; to your function. (You don't actually need to pass them back, since you're not changing them. &quot;Passing&quot; an argument doesn't make it disappear from the calling procedure.)

Change your function heading to:
Function asc_code(fld As Field, x As Integer)

Then change your function call to:
If asc_code(fld, x) >= 65 And asc_code(fld, x) <= 90 Or asc_code(fld, x) >= 97 And asc_code(fld, x) <= 122 Then

Another way to do it is to make both fld and x module-level variables, by Dim'ing them in the Declarations section of the module instead of inside your Sub procedure. Module-level variables are available to all procedures in the module, so you wouldn't have to pass them in that case. Rick Sprague
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top