Should be simple msgbox?

  • Thread starter Thread starter crich21
  • Start date Start date
C

crich21

What am I missing. Can someone please tell me why my msgbox is bein
displayed twice. For example once I click on ok it pops up again and
have to hit okay again to make it go away. Also is there a way to mak
the msgbox a double line instead of one long line of text?


Private Sub PartNumber_DblClick(Cancel As Integer)
On Error GoTo Err_PartNumber_Click

Dim stDocName As String
Dim stLinkCriteria As String

If Me.UMID = 1 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 2 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 6 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 8 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 12 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 13 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 14 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 15 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 16 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 17 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 18 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 19 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 20 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 21 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 22 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 23 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 24 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 25 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 26 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 27 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 28 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 29 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 30 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 33 Then
GoTo Err_PartNumber_Click
End If

stDocName = "frmPartBreakDown"

stLinkCriteria = "[PartID]=" & Me![PartID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Const cQuote = """" 'Thats two quotes
Forms!frmPartBreakdown!PartID.DefaultValue = cQuote & Me!PartID.Value
cQuote

Exit_PartNumber_Click:
Exit Sub

Err_PartNumber_Click:
MsgBox "This unit of measure is not supported by the Part Breakdow
Form. Please see designer for details.", vbInformation, "Information"
Resume Exit_PartNumber_Click

End Su
 
For each condition, use the Syntax
If Me.UMID = 1 Then Goto Err_PartNumber_Click

Rather than using "ElseIf".

Remove the "Resume" Statement, it is not needed here.

To split text for a message box over multiple lines, try
the syntax

MsgBox("This is line 01." & chr(13) & "This is line 02.")

HTH

Tony C.
 
Crich,

I can't actually spot an explanation why you are getting the message box
twice. But I have a comment and a suggestion.

I feel it would be simpler to do either of these approaches...

Private Sub PartNumber_DblClick(Cancel As Integer)
If Me.UMID In(1,2,6,8,33) Or Me.UMID Between 12 And 30 Then
MsgBox "This unit of measure is not supported by the Part Breakdown
Form. Please see designer for details.", vbInformation, "Information"
Else
DoCmd.OpenForm "frmPartBreakDown", , , "[PartID]=" & Me.PartID
Forms!frmPartBreakdown!PartID.DefaultValue = Me.PartID
End If
End Sub

Private Sub PartNumber_DblClick(Cancel As Integer)
Select Case Me.UMID
Case 1, 2, 6, 8, 12 To 30, 33
MsgBox "This unit of measure is not supported by the Part Breakdown
Form. Please see designer for details.", vbInformation, "Information"
Case Else
DoCmd.OpenForm "frmPartBreakDown", , , "[PartID]=" & Me.PartID
Forms!frmPartBreakdown!PartID.DefaultValue = Me.PartID
End Select
End Sub

So much for structure. I may be missing something here, but I don't
quite see the logic. You are opening the frmPartBreakDown form at a
specific record, based on PartID, and then setting the value of the
PartID's Default Value property. As far as I can see, this will be
totally ineffective, as the default value only applies in the case of a
new record, which is not what you've got. Therefore, it seems to me
that all you need is...

Private Sub PartNumber_DblClick(Cancel As Integer)
Select Case Me.UMID
Case 1, 2, 6, 8, 12 To 30, 33
MsgBox "This unit of measure is not supported by the Part Breakdown
Form. Please see designer for details.", vbInformation, "Information"
Case Else
DoCmd.OpenForm "frmPartBreakDown", , , "[PartID]=" & Me.PartID
End Select
End Sub

--
Steve Schapel, Microsoft Access MVP

What am I missing. Can someone please tell me why my msgbox is being
displayed twice. For example once I click on ok it pops up again and I
have to hit okay again to make it go away. Also is there a way to make
the msgbox a double line instead of one long line of text?


Private Sub PartNumber_DblClick(Cancel As Integer)
On Error GoTo Err_PartNumber_Click

Dim stDocName As String
Dim stLinkCriteria As String

If Me.UMID = 1 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 2 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 6 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 8 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 12 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 13 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 14 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 15 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 16 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 17 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 18 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 19 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 20 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 21 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 22 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 23 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 24 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 25 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 26 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 27 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 28 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 29 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 30 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 33 Then
GoTo Err_PartNumber_Click
End If

stDocName = "frmPartBreakDown"

stLinkCriteria = "[PartID]=" & Me![PartID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Const cQuote = """" 'Thats two quotes
Forms!frmPartBreakdown!PartID.DefaultValue = cQuote & Me!PartID.Value &
cQuote

Exit_PartNumber_Click:
Exit Sub

Err_PartNumber_Click:
MsgBox "This unit of measure is not supported by the Part Breakdown
Form. Please see designer for details.", vbInformation, "Information"
Resume Exit_PartNumber_Click

End Sub
 
Why don't you put those legal numbers in a table..and then use a combo box
with limit to list = yes. Your users will then be able to use a combo
box..and can't make a mistake! You really don't want to put such numbers
inside your code...least they have to be changed. With the combo box set tot
that list..you don't even need to check if they entered a non legal
number...since it will not be possible!

And, if you are going to keep your code...try using the select case
command...

Private Sub PartNumber_DblClick(Cancel As Integer)
On Error GoTo Err_PartNumber_Click

Dim stDocName As String
Dim stLinkCriteria As String

select case me.umid

case 1 to 2, 6, 8, 12 to 30, 33

goto Err_PartNumber_Click

end case

stDocName = "frmPartBreakDown"
stLinkCriteria = "[PartID] = " & Me![PartID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Const cQuote = """" 'Thats two quotes
Forms!frmPartBreakdown!PartID.DefaultValue = cQuote & Me!PartID.Value &
cQuote

Exit_PartNumber_Click:
Exit Sub

Err_PartNumber_Click:
MsgBox "This unit of measure is not supported by the Part Breakdown
Form. Please see designer for details.", vbInformation, "Information"
Resume Exit_PartNumber_Click
 
Steve Schapel said:
Crich,

I can't actually spot an explanation why you are getting the message box
twice. But I have a comment and a suggestion.

I feel it would be simpler to do either of these approaches...

Private Sub PartNumber_DblClick(Cancel As Integer)
If Me.UMID In(1,2,6,8,33) Or Me.UMID Between 12 And 30 Then
MsgBox "This unit of measure is not supported by the Part Breakdown
Form. Please see designer for details.", vbInformation, "Information"
Else
DoCmd.OpenForm "frmPartBreakDown", , , "[PartID]=" & Me.PartID
Forms!frmPartBreakdown!PartID.DefaultValue = Me.PartID
End If
End Sub

Private Sub PartNumber_DblClick(Cancel As Integer)
Select Case Me.UMID
Case 1, 2, 6, 8, 12 To 30, 33
MsgBox "This unit of measure is not supported by the Part Breakdown
Form. Please see designer for details.", vbInformation, "Information"
Case Else
DoCmd.OpenForm "frmPartBreakDown", , , "[PartID]=" & Me.PartID
Forms!frmPartBreakdown!PartID.DefaultValue = Me.PartID
End Select
End Sub

So much for structure. I may be missing something here, but I don't
quite see the logic. You are opening the frmPartBreakDown form at a
specific record, based on PartID, and then setting the value of the
PartID's Default Value property. As far as I can see, this will be
totally ineffective, as the default value only applies in the case of a
new record, which is not what you've got. Therefore, it seems to me
that all you need is...

Private Sub PartNumber_DblClick(Cancel As Integer)
Select Case Me.UMID
Case 1, 2, 6, 8, 12 To 30, 33
MsgBox "This unit of measure is not supported by the Part Breakdown
Form. Please see designer for details.", vbInformation, "Information"
Case Else
DoCmd.OpenForm "frmPartBreakDown", , , "[PartID]=" & Me.PartID
End Select
End Sub

--
Steve Schapel, Microsoft Access MVP

What am I missing. Can someone please tell me why my msgbox is being
displayed twice. For example once I click on ok it pops up again and I
have to hit okay again to make it go away. Also is there a way to make
the msgbox a double line instead of one long line of text?


Private Sub PartNumber_DblClick(Cancel As Integer)
On Error GoTo Err_PartNumber_Click

Dim stDocName As String
Dim stLinkCriteria As String

If Me.UMID = 1 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 2 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 6 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 8 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 12 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 13 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 14 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 15 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 16 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 17 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 18 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 19 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 20 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 21 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 22 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 23 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 24 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 25 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 26 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 27 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 28 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 29 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 30 Then
GoTo Err_PartNumber_Click
ElseIf Me.UMID = 33 Then
GoTo Err_PartNumber_Click
End If

stDocName = "frmPartBreakDown"

stLinkCriteria = "[PartID]=" & Me![PartID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Const cQuote = """" 'Thats two quotes
Forms!frmPartBreakdown!PartID.DefaultValue = cQuote & Me!PartID.Value &
cQuote

Exit_PartNumber_Click:
Exit Sub

Err_PartNumber_Click:
MsgBox "This unit of measure is not supported by the Part Breakdown
Form. Please see designer for details.", vbInformation, "Information"
Resume Exit_PartNumber_Click

End Sub
 
Whoops....bumped the send key...

I actually was going to say...*very* nice coding and style Steve!

I did not see your response until I placed mine here....

I can see I actually wasted my time on this one with your fine answer
sitting there all along!
 
Thank you all for the responses. I did change the code to use th
select case statement and it makes is so much cleaner. I am stil
getting a second message box for some reason, if I figure it out I wil
let you know. Thanks again
 
Crich,

As regards the doubling up of the messagbox, I suggest you try a
different event other than DblClick. DblClick of a textbox is never a
good idea. Maybe the Enter event, or Exit, or... even Click, whatever,
experiment. I am still not clear what this control is and how it and
its data relates to the other stuff to be able to give precise advice
right now.
 
Back
Top