Coding Won't Work

brett429

Registered User.
Local time
Today, 04:04
Joined
Apr 3, 2008
Messages
114
I'm very new to VB coding, so I am probably not doing this right. I have a field called PRIMARYDWELLINGVALUE that is filled in with a Currency amount (no decimals). There's a button that, once clicked, should display a message (CITIZENS) if the value entered in the field is between $149,999 and $750,001. Otherwise, it should not display. I've tried doing the code with and without commas, with and without dollar signs, etc. I can't seem to get it to work. Right now when I click the button with a "0" or "1" in the field, it does not display the message. But anything 2 and above displays the message. What am I doing wrong?

Private Sub PRIMARYBUTTON_Click()
If Me![PRIMARYDWELLINGVALUE] > "149,999" And Me![PRIMARYDWELLINGVALUE] < "750,001" Then
Me.CITIZENS.Visible = True

Else
Me.CITIZENS.Visible = False
End If
End Sub


Also, I'm going to end up having a long list of requirements for the message to display, based on multiple fields. In VB, what is the best way to accomplish this? Would you just keep sasying If...And...And...And...And...etc.?
 
If (cint(nz(Me![PRIMARYDWELLINGVALUE])) > 149999) And (cint(nz(Me![PRIMARYDWELLINGVALUE])) < 750001) Then

???
 
Code:
Private Sub PRIMARYBUTTON_Click()
    If Me![PRIMARYDWELLINGVALUE] > "149,999" And Me!PRIMARYDWELLINGVALUE] < "750,001" Then
        Me.CITIZENS.Visible = True

    Else
        Me.CITIZENS.Visible = False
    End If
End Sub
For one thing not using the code tags... for your code...
If you want to compare numbers you dont use quotes around them. Quotes are for using strings.
Also numbers in coding never have a thousands seperator...
Thus:
If Me![PRIMARYDWELLINGVALUE] > 149999 And Me!PRIMARYDWELLINGVALUE] < 750001 Then
 
Code:
Private Sub PRIMARYBUTTON_Click()
    If Me![PRIMARYDWELLINGVALUE] > "149,999" And Me!PRIMARYDWELLINGVALUE] < "750,001" Then
        Me.CITIZENS.Visible = True

    Else
        Me.CITIZENS.Visible = False
    End If
End Sub
For one thing not using the code tags... for your code...
If you want to compare numbers you dont use quotes around them. Quotes are for using strings.
Also numbers in coding never have a thousands seperator...
Thus:
If Me![PRIMARYDWELLINGVALUE] > 149999 And Me!PRIMARYDWELLINGVALUE] < 750001 Then

Ah, that was the problem! Thank you!

If you wouldn't mind taking a stab at my second question... I'm new to this, so I know it probably seems stupid. I'm going to actually have three different messages that display depending on the criteria entered into about 10 fields. I'm going to be adding to that coding above, so what is the best way to group the criteria together in the coding? For instance:

If the CITIZENS message is to display, two of the criteria are that the dwelling value is between $149,000 and $750,00 and another is that the dwelling age be less than 60 years. How would I best work that requirement into the coding? Another AND statement? For example:

If Me![PRIMARYDWELLINGVALUE] > 149999 And Me![PRIMARYDWELLINGVALUE] < 750001 And Me![DWELLINGAGE] < 60 Then

Thanks!
 
Yep that would be it.... except... You really should use Me. over Me!
 

Users who are viewing this thread

Back
Top Bottom