Variable not defined

C

carriey

Hi, this is my first time trying to write code like this (thanks to the
newsgroup for help!) and I haven't quite got it. When I click Debug, I get
an error "Variable not defined", and it goes to DLS.

I tried Dim Survey_System = String but that gives me error messages too.
Can someone please tell me how to define my variable? Here's the code:

Private Sub Survey_System_AfterUpdate()
If Survey_System = DLS Then
Me!LE = Left(Me!UWI, 3)
Me!LSD = Mid(Me!UWI, 4, 2)
Me!SEC = Mid(Me!UWI, 6, 2)
Me!TWP = Mid(Me!UWI, 8, 3)
Me!RGE = Mid(Me!UWI, 11, 2)
Me!MER = Mid(Me!UWI, 13, 2)
ElseIf Survey_System = NTS Then
Me!NTS_QUnit = Mid(Me!UWI, 4, 1)
Me!NTS_Except = Mid(Me!UWI, 5, 1)
Me!NTS_Unit = Mid(Me!UWI, 6, 3)
Me!NTS_4Block = Mid(Me!UWI, 7, 1)
Me!NTS_Map = Mid(Me!UWI, 10, 3)
Me!NTS_6Block = Mid(Me!UWI, 13, 1)
Me!NTS_7Block = Mid(Me!UWI, 14, 2)
End If
End Sub

Thanks!
 
D

Dirk Goldgar

carriey said:
Hi, this is my first time trying to write code like this (thanks to
the newsgroup for help!) and I haven't quite got it. When I click
Debug, I get an error "Variable not defined", and it goes to DLS.

I tried Dim Survey_System = String but that gives me error messages
too. Can someone please tell me how to define my variable? Here's
the code:

Private Sub Survey_System_AfterUpdate()
If Survey_System = DLS Then
Me!LE = Left(Me!UWI, 3)
Me!LSD = Mid(Me!UWI, 4, 2)
Me!SEC = Mid(Me!UWI, 6, 2)
Me!TWP = Mid(Me!UWI, 8, 3)
Me!RGE = Mid(Me!UWI, 11, 2)
Me!MER = Mid(Me!UWI, 13, 2)
ElseIf Survey_System = NTS Then
Me!NTS_QUnit = Mid(Me!UWI, 4, 1)
Me!NTS_Except = Mid(Me!UWI, 5, 1)
Me!NTS_Unit = Mid(Me!UWI, 6, 3)
Me!NTS_4Block = Mid(Me!UWI, 7, 1)
Me!NTS_Map = Mid(Me!UWI, 10, 3)
Me!NTS_6Block = Mid(Me!UWI, 13, 1)
Me!NTS_7Block = Mid(Me!UWI, 14, 2)
End If
End Sub

Thanks!

Is "DLS" supposed to be a literal value? If so, you have to enclose it
in quotes:

If Survey_System = "DLS" Then
 
K

Klatuu

Dim Survey_System As String
Dim DLS as String

Also, because you are getting the "variable not defined", that means Option
Explicit is in effect (This is a good thing)
If you are using Option Explicit, then all variables must be dimmed.

Now, on another note. Name Conventions: All objects should follow a naming
convention. I don't have a link for you, but if you stumble around in
Microsoft.com, you should be able to find info on suggested naming
conventions.

For example
String variables should start with str (strDLS, strSurvey_System)
Integer variables should start with int
Date with dtm (some use dte)

Text Boxes should start with txt
Combo Boxes with cbo
Command buttons cmd

And so on.

Does nothing for you except that when reading the code, it becomes obvious
what kind of object or data you are working with.
 

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