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

help with an IF statement 1

Status
Not open for further replies.

GabberGod

IS-IT--Management
Nov 16, 2003
73
AU
Private Sub Allocated_AfterUpdate()
If [Allocated] = True Then
[Job] = [Forms]![Jobs Entry]![Job]
End If
End Sub


Basicly if allocated gets ticked, then auto add a value from the form to that row of the subform.

i.e assign resource to job function
 
So what is your question?

BTW, it might be better form/performance as:

Private Sub Allocated_AfterUpdate()
If [Allocated] Then [Job] = [Forms]![Jobs Entry]![Job]
End Sub


Sam_F
"90% of the problem is asking the right question.
 
oh sorry, i thought that would e obvious,

why doesnt they piece of code i wrote work?

also how would moving the code all to one line increase performance??? its still the same number of characters to be parsed if you use a space or end of line character

you'll have to excuse my lack of ability, i dont use access often.
 
Generally speaking single line If statements will perform better... there are fewer calculations to make and fewer (3 instead of 5) lines of code to parse.

The first time-saver is that there is no need to compare The value of [Allocated] to the next value of True.

Also, there is no need to End If.

Admittedly, these performance gains will be negligible in one function, but throughout an entire complex database, it could be significant.

As for why this doesn't work, I do not believe there is enough info to be sure. Is Job a field on the active form? If so, try 'Me.Job'.

Private Sub Allocated_AfterUpdate()
If [Allocated] Then Me.[Job] = [Forms]![Jobs Entry]![Job]
End Sub

You should always reference subforms with their control names followed by .Form to avoid any confusion in case you had multiple subforms.


Sam_F
"90% of the problem is asking the right question.
 
How are ya GabberGod . . . . .

If [blue][Allocated][/blue] is on the [blue]MainForm[/blue] try this:
Code:
[blue]   Dim sfrm as Form

   set sfrm = Forms![purple][b]MainFormName[/b][/purple]![purple][b]subFormName[/b][/purple].Form

   If [Allocated] = True Then sfrm!Job = Me![Job]

   set sfrm = Nothing[/blue]
If [blue][Allocated][/blue] is on the [blue]subForm[/blue] try this:
Code:
[blue]   Dim frm as Form

   set frm = Forms![purple][b][purple][b]MainFormName[/b][/purple][/b][/purple]

   If [Allocated] = True Then Me!Job = frm![Job]

   set frm = Nothing[/blue]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top