Stumped on Syntax

S

SharonInGeorgia

I can't seem to get the Syntax right on IF, ELSE , End If. HELP........

Command Button 'Finished'

If frmUpdateAcctList.Desc Is <> "" Then
MsgBox "The Account List is Updated"
Docmd.Requery
Docmd.Close

If frmUpdateAcctList.Desc Is = "" Then
MsgBox "The Account Descriptions are Not Updated, Do you want to Update the
Account List Later", vbCancel,Yes

If Cancel, then return to the form

If Yes, msgbox "You will be asked to Update the Account List at a Later
time"vbOK
docmd.query (for the items that were updated)
docmd.close
 
K

Klatuu

The If Then Else End If construct is not that difficult. A Then is required
for every If. An End If is always required for every If. The Else is
optional.

If SomeCondition = True Then
Take Actions provided the condition evaluates to True
Else
Take Actions provided the condition does not evaluate to True
End If

I have modifed your code to give you a real life example. Please notice
the indentation. It makes conditional statements much easier to read.

If frmUpdateAcctList.Desc = "" Then
If MsgBox("The Account Descriptions are Not Updated, " _
& "Do you want to Update the Account List Later", _
vbQuestion + vbYesNo) = vbYes Then
msgbox "You will be asked to Update the Account List at a Later time"
Docmd.Close
'The Line below is not correct. I don't know what you are trying to do here
Else
docmd.query (for the items that were updated)
End If
Else
MsgBox "The Account List is Updated"
Docmd.Requery
End If
 
G

George Nicholson

Dim iResponse as Integer
Dim strMessage as String

If frmUpdateAcctList.Desc <> "" Then
MsgBox "The Account List is Updated"
Docmd.Requery
Docmd.Close
Else
'(If frmUpdateAcctList.Desc = "" )
strMessage = "The Account Descriptions are Not Updated, Do you want to
Update the Account List Later"
iResponse = MsgBox (strMessage, vbYesNo)
' Begin 2nd nested If...Then structure. This statement completed (End
If) before you complete the current/first If...Then.
If iResponse = vbNo Then
' Return to the form: i.e., do nothing
Else
' Yes
strMessage = "You will be asked to Update the Account List at a
Later time"
Msgbox strMessage, vbOK
docmd.query (for the items that were updated)
docmd.close
End If 'if iResponse = vbNo Then
End If 'If frmUpdateAcctList.Desc <> "" Then

HTH,
 
F

fredg

I can't seem to get the Syntax right on IF, ELSE , End If. HELP........

Command Button 'Finished'

If frmUpdateAcctList.Desc Is <> "" Then
MsgBox "The Account List is Updated"
Docmd.Requery
Docmd.Close

If frmUpdateAcctList.Desc Is = "" Then
MsgBox "The Account Descriptions are Not Updated, Do you want to Update the
Account List Later", vbCancel,Yes

If Cancel, then return to the form

If Yes, msgbox "You will be asked to Update the Account List at a Later
time"vbOK
docmd.query (for the items that were updated)
docmd.close


In addition to your other replies, Desc is a reserved Access/VBA/Jet
word and should not be used as a field or control name.
For additional reserved words, see the Microsoft KnowledgeBase article
for your version of Access:

109312 'Reserved Words in Microsoft Access' for Access 97
209187 'ACC2000: Reserved Words in Microsoft Access'
286335 'ACC2002: Reserved Words in Microsoft Access'
321266 'ACC2002: Microsoft Jet 4.0 Reserved Words'
 
K

Klatuu

If you use good naming conventions, you don't have to know or care what the
reserved words are.
 

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

Top