473,320 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Can I have 2 then statements after each instruction?

How can I have an If/Then statement perform 2 commands instead of just one per conditional IF statement?

Once a condition is true I want the then command to do 2 things not just one. The AND command doesnt work.

If RecordCount = 0 And Forms!devicemain![Category] = "Server" Then
Forms!connect![PortA] = Me![PortID] THEN
Forms!connect!SeeInterfaceZ.Form.Visible = False

ElseIf RecordCount = 0 And Forms!devicemain![Category] = "Switch" Or Forms!devicemain![Category] = "raritan" Then
Forms!connect![PortZ] = Forms!portmain![PortID]
End If


Exit_connectto_Click:
Exit Sub

Err_connectto_Click:
MsgBox Err.Description
Resume Exit_connectto_Click

End Sub
May 31 '07 #1
6 1432
Lysander
344 Expert 100+
How can I have an If/Then statement perform 2 commands instead of just one per conditional IF statement?

Once a condition is true I want the then command to do 2 things not just one. The AND command doesnt work.

If RecordCount = 0 And Forms!devicemain![Category] = "Server" Then
Forms!connect![PortA] = Me![PortID] THEN
Forms!connect!SeeInterfaceZ.Form.Visible = False

ElseIf RecordCount = 0 And Forms!devicemain![Category] = "Switch" Or Forms!devicemain![Category] = "raritan" Then
Forms!connect![PortZ] = Forms!portmain![PortID]
End If


Exit_connectto_Click:
Exit Sub

Err_connectto_Click:
MsgBox Err.Description
Resume Exit_connectto_Click

End Sub
I may be mis-understanding the problem, but you can have as many statements as you like for each IF clause, including nested IF statements.

The syntax is something like this
Expand|Select|Wrap|Line Numbers
  1. if something-is-true or something-else-is-true then
  2.      execute this statement
  3.      execute this one as well
  4.      keep executing statement till you get ELSE or END IF
  5. else
  6.      As before, do this statement
  7.      keep on going till you get END IF
  8. end if
  9.  
May 31 '07 #2
MMcCarthy
14,534 Expert Mod 8TB
As Lysander says you don't need the second Then statement, you just list all the statements you want executed in the order you want to execute them.

Expand|Select|Wrap|Line Numbers
  1.  
  2. If RecordCount = 0 And Forms!devicemain![Category] = "Server" Then
  3.     Forms!connect![PortA] = Me![PortID]
  4.     Forms!connect!SeeInterfaceZ.Form.Visible = False
  5. ElseIf RecordCount = 0 And Forms!devicemain![Category] = "Switch" Or Forms!devicemain![Category] = "raritan" Then
  6.     Forms!connect![PortZ] = Forms!portmain![PortID]
  7. End If
  8.  
  9.  
  10. Exit_connectto_Click:
  11.     Exit Sub
  12.  
  13. Err_connectto_Click:
  14.     MsgBox Err.Description
  15.     Resume Exit_connectto_Click
  16.  
  17. End Sub
Jun 1 '07 #3
Still doesnt work.

Subform SEEINTERFACEZ always disappears regardless if record >0
here is the entire code:
Expand|Select|Wrap|Line Numbers
  1.  Private Sub connectto_Click() 
  2. On Error GoTo Err_connectto_Click
  3.  
  4. Dim stDocName As String
  5. Dim stLinkCriteria As String
  6.  
  7. stDocName = "Connect"
  8.  
  9. stLinkCriteria = "[PortA]=" & Me![PortID] & "or [PortZ]=" & Me![PortID]
  10. DoCmd.OpenForm stDocName, , , stLinkCriteria
  11.  
  12. If RecordCount = 0 And Forms!devicemain![Category] = "Server" Then
  13. Forms!connect![PortA] = Me![PortID]
  14. Forms!connect!SeeInterfaceZ.Form.Visible = False
  15. ElseIf RecordCount = 0 And Forms!devicemain![Category] = "Switch" Or Forms!devicemain![Category] = "raritan" Then
  16. Forms!connect![PortZ] = Me![PortID]
  17. Forms!connect!SeeInterfaceA.Form.Visible = False
  18. End If
  19.  
  20. Exit_connectto_Click:
  21. Exit Sub
  22.  
  23. Err_connectto_Click:
  24. MsgBox Err.Description
  25. Resume Exit_connectto_Click
  26.  
  27. End Sub
  28.  
Jun 1 '07 #4
MMcCarthy
14,534 Expert Mod 8TB
You have to put this in the load event of the Connect form. You can't get the record count from outside the form.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. Dim rs As DAO.Recordset
  3.  
  4.     Set rs = Me.RecordsetClone
  5.  
  6.     If rs.RecordCount = 0 Then
  7.        If Forms!devicemain![Category] = "Server" Then
  8.            Me![PortA] = Forms!devicemain![PortID]
  9.            Me!SeeInterfaceZ.Form.Visible = False
  10.        ElseIf Forms!devicemain![Category] = "Switch" Or Forms!devicemain![Category] = "raritan" Then
  11.            Me![PortZ] = Forms!devicemain![PortID]
  12.            Me!SeeInterfaceA.Form.Visible = False
  13.        End If
  14.     End If
  15.  
  16.     Set rs = Nothing
  17.  
  18. End Sub
  19.  
Jun 1 '07 #5
THANKS mmccarthy !

It worked like a charm. I really need to read-up on the what 'oncurrent', 'onload' etc mean. I was working on this for 2-weeks.

Thanks Again!
Jun 2 '07 #6
MMcCarthy
14,534 Expert Mod 8TB
THANKS mmccarthy !

It worked like a charm. I really need to read-up on the what 'oncurrent', 'onload' etc mean. I was working on this for 2-weeks.

Thanks Again!
No problem
Jun 2 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Hayko Riemenschneider | last post by:
Hi! I've got me an XSL tranformation stylesheet for my XML file. In the XSL file I now wish to use PHP to do some scripting. So I thought I'll use the PIs like this: ...
1
by: Brittany | last post by:
can someone explain to me what if else staments do and what while statements do.
3
by: Phil | last post by:
Hi everybody, I am a XSLT beginner and the following problem really makes me crazy ! I have a main "contacts.xml" document which contains references to several contact data XML files. My aim...
18
by: Haines Brown | last post by:
In XHTML docs, I find that the W3 Validator raises an objection to my headers without actually invalidating the document. Not in <title></title>, but in meta name="abstract" and...
2
by: serge | last post by:
/* This is a long post. You can paste the whole message in the SQL Query Analyzer. I have a scenario where there are records with values pointing to wrong records and I need to fix them using an...
12
by: Martin Johansen | last post by:
In C, what do you call that which is separated by semicolon? what is the difference between an expression and a statement? Thank you.
1
by: Shane Hathaway | last post by:
Let's talk about the problem I really want help with. I brought up a proposal earlier, but it was only half serious. I realize Python is too sacred to accept such a heretical change. ;-) ...
2
by: ojorus | last post by:
Hi! Some questions regarding the mysqli-extension (php5) 1) Prepared statements: If I understand things right, prepared statements will give better performance if you make several similar...
5
by: sam_cit | last post by:
Hi Everyone, I read somewhere that there are some compile time operations behind switch-case, which is why it can work for cases which evaluates to an integer or character and not strings and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.