help with IF statment please

Jon123

Registered User.
Local time
Today, 06:42
Joined
Aug 29, 2003
Messages
668
This one is driving me nuts I have to ask to If statements and I cant seem to get it right is there a better way. This is the code

On Error GoTo Err_Readme_Click
If DCount("[Part Number]", "[tble-Parts History]", "[Part Number] = '" & Me.[Part Number] & "' AND [system] = " & Me.[system] & " AND [Chamber] = '" & Me.[Chamber] & "' AND [Currently in use] = True") > 0 Then
Dim StdResponse As Integer
DoCmd.SetWarnings False
StdResponse = MsgBox("This Part is already configured in this chamber. Is this part replacing the one currently configured?", 52)
If StdResponse = 6 Then 'Yes
Dim stDocName As String
stDocName = "Qry-parts reset current"
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.close acForm, "Frm-Adding Process Parts"
DoCmd.close acForm, "Frm-Process kit Parts Installed"
DoCmd.OpenForm "Frm-Parts Main"
Else ' No
End If
Dim StdResponse1 As Integer
DoCmd.SetWarnings False
StdResponse1 = MsgBox("Is this a multiple used part in this chamber?", 52)
If StdResponse1 = 6 Then 'Yes
'Part ok
DoCmd.close acForm, "Frm-Adding Process Parts"
DoCmd.close acForm, "Frm-Process kit Parts Installed"
DoCmd.OpenForm "Frm-Parts Main"
Exit Sub
Else
'User said No
Me.[Part Number] = Null
Me.[Part Description] = Null
Me.[Currently in use] = False
DoCmd.close acForm, "Frm-Adding Process Parts"
DoCmd.close acForm, "Frm-Process kit Parts Installed"
DoCmd.OpenForm "Frm-Parts Main"
End If
Exit Sub
Exit_Readme_Click:
Exit Sub
Err_Readme_Click:
MsgBox Err.Description
Resume Exit_Readme_Click
End If
End Sub
 
I am not sure that all of the If() Blocks are doing what you want them to. Also, the Err_Readme_Click appears to be inside the final If() Block, when I think it should be outside. If you reformat the code and use the code block markers (see below) we will be able to see your intentions better.

Code:
[COLOR=red][B]Place Formatted Code Here[/B][/COLOR]
[/ code]
-^ Remove this space
 
From what I can see, your first if block, for the second if, it should be:

elseIf StdResponse = 6 Then

and you seem to have an extra end if, whether you want it just before the end sub or before exit sub, I don't know.

Have you put it in the code window and see? Access should have picked out those mistakes.
 
don't forget to use the code tag for your VB code.

[ code]

....put your VB code here so it is easier for us to read

[ /code]

without the space after the [


Thanks.
 
don't forget to use the code tag for your VB code.

[ code]

....put your VB code here so it is easier for us to read

[ /code]

without the space after the [


Thanks.

Good Point ezfriend - Here's a visual:

codetag001.png
 

Users who are viewing this thread

Back
Top Bottom