Why is this not working?

Funkbuqet

Registered User.
Local time
Today, 14:36
Joined
Oct 30, 2010
Messages
50
I am trying to get the information in one feild to complile based on the information in 3 other feilds. Basicly, I have a SegmentID feild tat I want the data to be created from the County, Division, and section values.
So if County=FLES, Division=1, and Section=-001 Then SegmentID=FLES1-001

Here is the Code

Private Sub ScatSegment_AfterUpdate()
Dim cName As String
Dim dName As String
Dim sNumber As String
Dim sID As String

Forms!Segments!CountyID.SetFocus
cName = Forms!Segments!CountyID.Value
Forms!Segments!Division.SetFocus
dName = Forms!Segments!Division.Text
Forms!Segments!ScatSegment.SetFocus
sNumber = Forms!Segments!ScatSegment.Text


sID = cName & dName & sNumber
'This line is the offender as far as I can tell. When I palce a stop point here all of the values to the right of the = are correctly assigned but when I place the cursor over sID it says sID="". Why is it not combining the 3 values???

If Len(sID) = 8 Then
Forms!Segments!SegmentID.SetFocus
If Forms!Segments!SegmentID = "" Then
Forms!Segments!SegmentID = sID
End If
End If

End Sub

Thank you for any help you can provide
 
At the point the debugger is on that line, it will not have been executed yet. Have you tried going another line (F8) and see if the value gets assigned correctly? In your example, the length would be 9, not 8 (the dash counts).
 
By the way, you don't need any of the SetFocus lines, as long as you use .Value instead of .Text.
 
Firstly if you have those three values already stored individually in each record, why do you need to concatenate them and store them together, as this is something that can be done at form or report level for display purposes.

Your code could be bit simplified to;
Code:
Private Sub ScatSegment_AfterUpdate()


If Me.SegmentID <> "" Or Not IsNull(Me.SegmentID) Then
     Exit Sub
End If


Me.SegmentID = Me.CountyID.Value & Me.Division.Text & Me.ScatSegment.Text

End Sub
 
Code:
Me.SegmentID = Me.CountyID.Value & Me.Division.Text & Me.ScatSegment.Text

Or perhaps

Me.SegmentID = Me.CountyID.Value & Me.Division.Value & Me.ScatSegment.Value

;)
 
Thank you very much that worked well. The reason I have to do it this way is what I am actually interested in storing in the database is SegmentID, but the form is filled out by feild teams and the boss wants it broken down to make it simpler for them.

What does the Me. represent and how can it be used more broadly?
 
Me is a shortcut to referring to the object whose module it appears in. In your case, the form. Within the form Segments, these mean the same thing:

Forms!Segments!CountyID.Value
Me!CountyID.Value

In the code behind a report named "Test", Me would refer to that report. One advantage to using it is that as soon as you type "Me." you'll get a dropdown of available members, properties and methods. Helps avoid typos.
 
A more thorough explanation of ME:
This is a programming shortcut which lets the programmer refer to the current CLASS object. Most of the time, in Access, you would be referring to a form or report using this. It can also apply to custom classes as well, but is less prevalent unless custom classes are being used.
Let's say you have a form named "frmMain" and you have a text box there called "txtEntry" and you wanted to refer to that text box in code. A fully-qualified reference would be Forms!frmMain.txtEntry but you could also refer to it using the shortcut (as long as the code is ON frmMain): Me.txtEntry
 
Excellent, thats what I was hoping it did. Thank you for the clarification.
 
It you want scripts that don't give a toss which form or report calls them, you can create Modules using:

With CodeContextObject

So me. becomes simply . the me is superfluous.

Forms!Segments!CountyID.Value
Forms!Clients!CountyID.Value
Forms!Suppliers!CountyID.Value
Me!CountyID.Value

ALL become .CountyID.Value

Simon
 

Users who are viewing this thread

Back
Top Bottom