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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting the Default cannot be that hard! Right?

Status
Not open for further replies.

DaveMac

Technical User
Apr 9, 2000
161
US
Hello, I have copied this code from a FAQ and it looks like it will do exactly what I need. There is one small problem, it does nothing not even throw and error. What am I missing????? I have two text boxes on a form that are from a table that I want to set to the previous records values. So how do I fix this code or just get my result which is to set the default value of a text box to the previous records value.?




Private Sub Consumed_Carton_ID_AfterUpdate()

Dim ctl As Control
On Error GoTo Consumed_Carton_ID_AfterUpdate_Err

'Set the new records default values to the previous records values
For Each ctl In Me.Controls
'any records needing a previous value set the tag name to "Carryforward"
If ctl.Tag = "CarryForward" Then
ctl.DefaultValue = """" & ctl.Value & """"
End If
Next ctl
Consumed_Carton_ID_AfterUpdate_Exit:
Set ctl = Nothing
Exit Sub
Consumed_Carton_ID_AfterUpdate_Err:
'Alert the user that an error has occurred
Call ErrorHandler(Err.Number, Err.Description, "Consumed_Carton_ID_AfterUpdate")

Resume Consumed_Carton_ID_AfterUpdate_Exit

End Sub
 
Yes each of the two text boxes has a TAG = "Carryforward
 
How are ya DaveMac . . .
TheAceMan1 said:
[blue]When entering text in the [purple]Tag[/purple] property of a control, [red]Do Not Use Any Quotation Marks![/red] ...[/blue]
I can't explain why (found out the hard way myself), I can only say ... [blue]thats the way it is.[/blue]

What actually happens is the following:
Code:
[blue]    If ctl.Tag = [red][b]""[/b][/red]CarryForward[red][b]""[/b][/red] Then[/blue]
Note the double, double quotes! ... No way this compares!

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
TheAceMan1, I think you meant this ?
If ctl.Tag = """CarryForward""" Then
 
Howdy PHV . . .

In 2k its as Ive shown. Either way it can't compare . . .

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
In 2k its as Ive shown
And you don't raise a compile error like 'End of instruction expected' ???
 
PHV . . .

With "CarryForward" entered manually in the tag property (including quotes), what I present is what shows in a watch for ctl.Tag during a breakpoint. I'm just showing what the watch reveals. A better rendetion would be:
Code:
[blue]If ""CarryForward"" = "CarryForward" Then[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
I'm just showing what the watch reveals
Sorry, but you've posted VBA code, with syntax error, thus my post timestamped 7 Jan 09 4:33.
 
PHV . . .

In VBA we have:
Code:
[blue]   If ctl.Tag = "CarryForward" Then[/blue]
[blue]This is legimate and will compile![/blue] However the watch shows what ctl.Tag returns. Try it for yourself and see . . .

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 

So wht happen to [blue]DaveMac?[/blue] [surprise]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top