Arrey

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
when i start a programm every option, which is before (12) makes two things:
open a report (which is ok) and open a msgbox from section (12) (what should
happen olny when i choose option (12)). When i choose option (12) it opens
itself and option (13). What is wrong in the code? Thanks.
..................
If lstZakupy.Selected(11) Then DoCmd.OpenReport ("gry_Lief_AGrp"),
acViewPreview

If lstZakupy.Selected(12) Then DoCmd.RunMacro ("Auslauf_Update_1")
If DCount("[ArNr]", "Auslauf_Temp") = 0 Then
If MsgBox("Text", vbYesNo) = vbYes Then
DoCmd.OpenForm ("AuslaufArt_1")
End If
Else
DoCmd.OpenForm ("AuslaufArt_2")
End If

If lstZakupy.Selected(13) Then DoCmd.RunMacro ("Gesperrt_Update_1")
 
Phil said:
Hi,
when i start a programm every option, which is before (12) makes two
things: open a report (which is ok) and open a msgbox from section
(12) (what should happen olny when i choose option (12)). When i
choose option (12) it opens itself and option (13). What is wrong in
the code? Thanks. .................
If lstZakupy.Selected(11) Then DoCmd.OpenReport ("gry_Lief_AGrp"),
acViewPreview

If lstZakupy.Selected(12) Then DoCmd.RunMacro ("Auslauf_Update_1")
If DCount("[ArNr]", "Auslauf_Temp") = 0 Then
If MsgBox("Text", vbYesNo) = vbYes Then
DoCmd.OpenForm ("AuslaufArt_1")
End If
Else
DoCmd.OpenForm ("AuslaufArt_2")
End If

If lstZakupy.Selected(13) Then DoCmd.RunMacro ("Gesperrt_Update_1")

I'm not sure I understand exactly what you are saying, but in the code
you posted these lines:
If DCount("[ArNr]", "Auslauf_Temp") = 0 Then
If MsgBox("Text", vbYesNo) = vbYes Then
DoCmd.OpenForm ("AuslaufArt_1")
End If
Else
DoCmd.OpenForm ("AuslaufArt_2")
End If

will always be executed. Maybe you intended for them to be executed
only when lstZakupy.Selected(12) is True. If that is what you wanted,
you should write the code for that option like this:

'----- start of revised code -----
If lstZakupy.Selected(12) Then
DoCmd.RunMacro ("Auslauf_Update_1")
If DCount("[ArNr]", "Auslauf_Temp") = 0 Then
If MsgBox("Text", vbYesNo) = vbYes Then
DoCmd.OpenForm ("AuslaufArt_1")
End If
Else
DoCmd.OpenForm ("AuslaufArt_2")
End If
End If
'----- end of revised code -----

Is lstZakupy a multiselect list box? If it's not multiselect, you
should probably be using an If ... Then ... ElseIf structure to avoid
unnecessary tests, like this:

If lstZakupy.Selected(0) Then
' handle first option ...
ElseIf lstZakupy.Selected(1) Then
' handle second option ...
ElseIf lstZakupy.Selected(2) Then
' handle third option ...
' ... and so on
End If
 
Back
Top