If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
If, Then, Else
Hi,
I'm a bit confused and hope someone can help. I'm just learning code and can't figure out why I keep getting an compile error; Else Without If on the following code. Thanks in advance. Private Sub Command930_Click() On Error GoTo Err_Command930_Click Dim stDocName As String Dim stLinkCriteria As String If SSN.Value = -1 And ysnName.Value = -1 _ And Recipient_of_PHI = "Entity" Or Recipient_of_PHI = "Person" Then _ stDocName = "frmAction1-5" DoCmd.OpenForm stDocName, , , stLinkCriteria Else stDocName = "frmAction5" DoCmd.OpenForm stDocName, , , stLinkCriteria End If Exit_Command930_Click: Exit Sub Err_Command930_Click: MsgBox Err.Description Resume Exit_Command930_Click End Sub |
#2
|
|||
|
|||
If, Then, Else
"Ann" wrote in message
... Hi, I'm a bit confused and hope someone can help. I'm just learning code and can't figure out why I keep getting an compile error; Else Without If on the following code. Thanks in advance. Private Sub Command930_Click() On Error GoTo Err_Command930_Click Dim stDocName As String Dim stLinkCriteria As String If SSN.Value = -1 And ysnName.Value = -1 _ And Recipient_of_PHI = "Entity" Or Recipient_of_PHI = "Person" Then _ stDocName = "frmAction1-5" DoCmd.OpenForm stDocName, , , stLinkCriteria Else stDocName = "frmAction5" DoCmd.OpenForm stDocName, , , stLinkCriteria End If Exit_Command930_Click: Exit Sub Err_Command930_Click: MsgBox Err.Description Resume Exit_Command930_Click End Sub I believe it's because you have a line-continuation character after the keyword Then: And Recipient_of_PHI = "Entity" Or Recipient_of_PHI = "Person" Then _ It should just be And Recipient_of_PHI = "Entity" Or Recipient_of_PHI = "Person" Then For a block If, the statements that follow the If are not continuations of the If statement. -- Dirk Goldgar, MS Access MVP Access tips: www.datagnostics.com/tips.html (please reply to the newsgroup) |
#3
|
|||
|
|||
If, Then, Else
That was it! Thank you.
"Dirk Goldgar" wrote: "Ann" wrote in message ... Hi, I'm a bit confused and hope someone can help. I'm just learning code and can't figure out why I keep getting an compile error; Else Without If on the following code. Thanks in advance. Private Sub Command930_Click() On Error GoTo Err_Command930_Click Dim stDocName As String Dim stLinkCriteria As String If SSN.Value = -1 And ysnName.Value = -1 _ And Recipient_of_PHI = "Entity" Or Recipient_of_PHI = "Person" Then _ stDocName = "frmAction1-5" DoCmd.OpenForm stDocName, , , stLinkCriteria Else stDocName = "frmAction5" DoCmd.OpenForm stDocName, , , stLinkCriteria End If Exit_Command930_Click: Exit Sub Err_Command930_Click: MsgBox Err.Description Resume Exit_Command930_Click End Sub I believe it's because you have a line-continuation character after the keyword Then: And Recipient_of_PHI = "Entity" Or Recipient_of_PHI = "Person" Then _ It should just be And Recipient_of_PHI = "Entity" Or Recipient_of_PHI = "Person" Then For a block If, the statements that follow the If are not continuations of the If statement. -- Dirk Goldgar, MS Access MVP Access tips: www.datagnostics.com/tips.html (please reply to the newsgroup) |
#4
|
|||
|
|||
If, Then, Else
On Thu, 5 Nov 2009 11:27:01 -0800, Ann wrote:
Hi, I'm a bit confused and hope someone can help. I'm just learning code and can't figure out why I keep getting an compile error; Else Without If on the following code. Thanks in advance. Private Sub Command930_Click() On Error GoTo Err_Command930_Click Dim stDocName As String Dim stLinkCriteria As String If SSN.Value = -1 And ysnName.Value = -1 _ And Recipient_of_PHI = "Entity" Or Recipient_of_PHI = "Person" Then _ stDocName = "frmAction1-5" DoCmd.OpenForm stDocName, , , stLinkCriteria Else stDocName = "frmAction5" DoCmd.OpenForm stDocName, , , stLinkCriteria End If Exit_Command930_Click: Exit Sub Err_Command930_Click: MsgBox Err.Description Resume Exit_Command930_Click End Sub You need to remove the underscore line continuation character after the Then. The If statement has two syntaxes: the more common If Condition Then statements if true Else statements if false End If and the "one line if" If Condition Then statement if true Your lines If SSN.Value = -1 And ysnName.Value = -1 _ And Recipient_of_PHI = "Entity" Or Recipient_of_PHI = "Person" Then _ stDocName = "frmAction1-5" are being read as a single line - since you have the line continuation characters; the line stDocName = "frmAction1-5" is the end of the entire IF block, as far as Access is concerned, so when you get to the ELSE further down, it's not seen as being part of an IF block. -- John W. Vinson [MVP] |
Thread Tools | |
Display Modes | |
|
|