if's - End if's blocks and errors (1 Viewer)

sonny123

Registered User.
Local time
Today, 04:54
Joined
Apr 8, 2011
Messages
31
i'm a bit confused with If's and end if, I am quite new to access and VBA so perhaps im missing the bleeding obvious

I have discovered (i think) that If a condition is met and I only want to do one thing , i only need If/then
but if I want to do more than one thing when a condition is met I need an 'end if'

basically I want to set three fields in a form when a button is pressed
but i only want to set them if the value of one of those fields is Null.


Ive tried a few things syntax wise but keep getting "block" errors ???

here is what I have

Code:
Private Sub GetNumbers_Click()

If Me![thisNumber] = Null Then
[INDENT]Me![thisNumber] = Nz(DMax("[TNumber]", "[Main]"), 0) + 1
Me![concatentaedRef] = Me![thisNumber] & Me![Suffix]
Me![OtherNumber] = Nz(DMax("[TOtherNumber]", "[Main]", "[TDateEntered] = #" & Forms!Main!DateEntered & "# "), 0) + 1[/INDENT]
End If

End Sub

please point me in the right direction
 

boblarson

Smeghead
Local time
, 20:54
Joined
Jan 12, 2001
Messages
32,059
Code:
Private Sub GetNumbers_Click()
 
    If IsNull(Me![thisNumber]) Then
 
        Me![thisNumber] = Nz(DMax("[TNumber]", "[Main]"), 0) + 1
 
        Me![concatentaedRef] = Me![thisNumber] & Me![Suffix]
 
        Me![OtherNumber] = Nz(DMax("[TOtherNumber]", "[Main]", "[TDateEntered] = #" & Forms!Main!DateEntered & "#"), 0) + 1
 
    End If
 
End Sub
 

missinglinq

AWF VIP
Local time
, 23:54
Joined
Jun 20, 2003
Messages
6,420
As to youe confusion, yes, when an If...Then construct can be written on a single line, such as

Code:
[B]If[/B] Me.Dessert = "Pie" [B]Then[/B] Me.Filling = "apple"
the End If is omitted.

If the construct requires more than one line, such as the code Bob gave you, it has to have the End If statement.

Code:
[B]If[/B] Me.Dessert = Pie" [B]Then[/B] 
  Me.Filling = "apple" 
  Me.Crust = "Thin"
[B]End If[/B]

Linq ;0)>
 

sonny123

Registered User.
Local time
Today, 04:54
Joined
Apr 8, 2011
Messages
31
thanks very much

it looks like my syntax; in respect of the way I was saying "If the value = null"
rather than saying If isNull(the value i'm referring to) then
do this
do that
end the If block

time for some more experiments:)
 

sonny123

Registered User.
Local time
Today, 04:54
Joined
Apr 8, 2011
Messages
31
Yay! that works nicely
thanks very much....

BTW I still cannot find a 'mark thread solved' thingy any where????
 

Users who are viewing this thread

Top Bottom