please help with simple syntax question

L

lance

Hi all,

I was hoping someone could help me with a rather simple syntax
question:


I have a variable called "partnum" and "plist" ... "plist" is
a currency value amount.


I have on a form (form is called "invoices") 4 different text boxes,
partscharge1 , partscharge2 , partscharge3 and partscharge4 .


all I want to do is make the appropiate partscharge text box equal to
the
"plist" variable. By appropiate I mean the value of "partnum"


Here is the line I need the proper syntax for:


Forms![invoices]!partscharge<<partnum variable>> = plist


The above line is the wrong syntax........ If partnum = 4 i want it
to
be equal to:


Forms![invoices]!partscharge4 = plist


If partnum = 3 then I would want it to equal to the statement:


Forms![invoices]!partscharge3 = plist


Basically , instead of having to type the actual number, i want that
number to be gotten from the variable "partnum" , so i can assign the
plist amount to the correct partscharge textbox.


could someone kindly give me the correct line syntax.... I'm know
very little about vb coding and need help with this simple
syntax question.


Please email me at (e-mail address removed) - your help is so much
appreciated!!
 
G

Graham R Seach

Lance,

There are two ways to do this:

OPTION 1
If partnum = 1 Then
Forms![invoices]!partscharge1 = plist
ElseIf partnum = 2 Then
Forms![invoices]!partscharge2 = plist
If partnum = 3 Then
Forms![invoices]!partscharge3 = plist
ElseIf partnum = 4 Then
Forms![invoices]!partscharge4 = plist
Else
'What happens if partnum < 1 or > 4 ??
End If

OPTION 2
Forms!invoices.("partscharge" & CStr(partnum)) = plist

Option 2 can generate an error if partnum < 1 or > 4.

------------------------------------------------------
If the code is running in the context of the invoices form, then you can
dispense with "Forms!invoices", and simply use "Me". For example, all the
above code could be written thus:

OPTION 1
If partnum = 1 Then
Me!partscharge1 = plist
ElseIf partnum = 2 Then
Me!partscharge2 = plist
If partnum = 3 Then
Me!partscharge3 = plist
ElseIf partnum = 4 Then
Me!partscharge4 = plist
Else
'What happens if partnum < 1 or > 4 ??
End If

OPTION 2
Me("partscharge" & CStr(partnum)) = plist

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
L

lance

Lance,

There are two ways to do this:

OPTION 1
    If partnum = 1 Then
        Forms![invoices]!partscharge1 = plist
    ElseIf partnum = 2 Then
        Forms![invoices]!partscharge2 = plist
    If partnum = 3 Then
        Forms![invoices]!partscharge3 = plist
    ElseIf partnum = 4 Then
        Forms![invoices]!partscharge4 = plist
    Else
        'What happens if partnum < 1 or > 4 ??
    End If

OPTION 2
    Forms!invoices.("partscharge" & CStr(partnum)) = plist

Option 2 can generate an error if partnum < 1 or > 4.

------------------------------------------------------
If the code is running in the context of the invoices form, then you can
dispense with "Forms!invoices", and simply use "Me". For example, all the
above code could be written thus:

OPTION 1
    If partnum = 1 Then
        Me!partscharge1 = plist
    ElseIf partnum = 2 Then
        Me!partscharge2 = plist
    If partnum = 3 Then
        Me!partscharge3 = plist
    ElseIf partnum = 4 Then
        Me!partscharge4 = plist
    Else
        'What happens if partnum < 1 or > 4 ??
    End If

OPTION 2
    Me("partscharge" & CStr(partnum)) = plist

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia




I was hoping someone could help me with a rather simple syntax
question:
I have a variable called "partnum" and "plist" ...  "plist" is
a currency value amount.
I have on a form (form is called "invoices") 4 different text boxes,
partscharge1 , partscharge2 , partscharge3 and partscharge4 .
all I want to do is make the appropiate partscharge text box equal to
the
"plist" variable.  By appropiate I mean the value of "partnum"
Here is the line I need the proper syntax for:
Forms![invoices]!partscharge<<partnum variable>> = plist
The above line is the wrong syntax........  If partnum = 4 i want it
to
be equal to:
Forms![invoices]!partscharge4 = plist
If partnum = 3 then I would want it to equal to the statement:
Forms![invoices]!partscharge3 = plist
Basically , instead of having to type the actual number, i want that
number to be gotten from the variable "partnum" , so i can assign the
plist amount to the correct partscharge textbox.
could someone kindly give me the correct line syntax....  I'm know
very little about vb coding and need help with this simple
syntax question.
Please email me at (e-mail address removed) - your help is so much
appreciated!!- Hide quoted text -

- Show quoted text -


Thanks so much! My code was actually running outside of the context
of the invoices form, its working good now! Thanks Again!!
 

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

Similar Threads

need help with syntax 1
ancestor:: XML syntax 11
List casting question 2
syntax for default value 1
looking for help with syntax error 5
Syntax HELP 1
Syntax Question 1
Please Help with syntax 6

Top