Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!
  1. Monthly (Recurring) Target: $300 :: Achieved: $95
      Become a Supporter    ::   Make a Contribution   

Help with error message please

Discussion in 'Information Technology' started by Sheila D, Jul 28, 2006.

  1. Sheila D

    Sheila D
    Expand Collapse
    Guest

    Hi

    I don't know very much about VB so please be gentle with me!
    I have a form with drop down selector list and then a command button which
    opens another form with the record chosen from the drop down list. I created
    the command button code using the wizard so looks like this
    Private Sub OK_Click()
    On Error GoTo Err_OK_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "F_Delete Contact"

    stLinkCriteria = "[Company Number]=" & Me![Choose Company]
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Exit_OK_Click:
    Exit Sub

    Err_OK_Click:
    MsgBox err.procedure
    Resume Exit_OK_Click

    This works fine but if the user just clicks the button without making a
    selection comes up with standard error message. I'd like to replace this
    message with a prompt that says 'You must select Company first' with an OK
    button that then takes them back to the selection box. What's the best (and
    easiest) way to do this please.
    Thanks - Sheila
     
  2. Loading...


  3. Ofer Cohen

    Ofer Cohen
    Expand Collapse
    Guest

    By adding a check if no value was entered

    Private Sub OK_Click()
    On Error GoTo Err_OK_Click

    Dim stDocName As String
    Dim stLinkCriteria As String
    If IsNull(Me![Choose Company]) Then
    Msgbox "You must select Company first"
    Else
    stDocName = "F_Delete Contact"

    stLinkCriteria = "[Company Number]=" & Me![Choose Company]
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    End If

    Exit_OK_Click:
    Exit Sub

    Err_OK_Click:
    MsgBox err.procedure
    Resume Exit_OK_Click

    --
    Good Luck
    BS"D


    "Sheila D" wrote:

    > Hi
    >
    > I don't know very much about VB so please be gentle with me!
    > I have a form with drop down selector list and then a command button which
    > opens another form with the record chosen from the drop down list. I created
    > the command button code using the wizard so looks like this
    > Private Sub OK_Click()
    > On Error GoTo Err_OK_Click
    >
    > Dim stDocName As String
    > Dim stLinkCriteria As String
    >
    > stDocName = "F_Delete Contact"
    >
    > stLinkCriteria = "[Company Number]=" & Me![Choose Company]
    > DoCmd.OpenForm stDocName, , , stLinkCriteria
    >
    > Exit_OK_Click:
    > Exit Sub
    >
    > Err_OK_Click:
    > MsgBox err.procedure
    > Resume Exit_OK_Click
    >
    > This works fine but if the user just clicks the button without making a
    > selection comes up with standard error message. I'd like to replace this
    > message with a prompt that says 'You must select Company first' with an OK
    > button that then takes them back to the selection box. What's the best (and
    > easiest) way to do this please.
    > Thanks - Sheila
     
  4. Sheila D

    Sheila D
    Expand Collapse
    Guest

    Fantastic - thanks

    "Ofer Cohen" wrote:

    > By adding a check if no value was entered
    >
    > Private Sub OK_Click()
    > On Error GoTo Err_OK_Click
    >
    > Dim stDocName As String
    > Dim stLinkCriteria As String
    > If IsNull(Me![Choose Company]) Then
    > Msgbox "You must select Company first"
    > Else
    > stDocName = "F_Delete Contact"
    >
    > stLinkCriteria = "[Company Number]=" & Me![Choose Company]
    > DoCmd.OpenForm stDocName, , , stLinkCriteria
    > End If
    >
    > Exit_OK_Click:
    > Exit Sub
    >
    > Err_OK_Click:
    > MsgBox err.procedure
    > Resume Exit_OK_Click
    >
    > --
    > Good Luck
    > BS"D
    >
    >
    > "Sheila D" wrote:
    >
    > > Hi
    > >
    > > I don't know very much about VB so please be gentle with me!
    > > I have a form with drop down selector list and then a command button which
    > > opens another form with the record chosen from the drop down list. I created
    > > the command button code using the wizard so looks like this
    > > Private Sub OK_Click()
    > > On Error GoTo Err_OK_Click
    > >
    > > Dim stDocName As String
    > > Dim stLinkCriteria As String
    > >
    > > stDocName = "F_Delete Contact"
    > >
    > > stLinkCriteria = "[Company Number]=" & Me![Choose Company]
    > > DoCmd.OpenForm stDocName, , , stLinkCriteria
    > >
    > > Exit_OK_Click:
    > > Exit Sub
    > >
    > > Err_OK_Click:
    > > MsgBox err.procedure
    > > Resume Exit_OK_Click
    > >
    > > This works fine but if the user just clicks the button without making a
    > > selection comes up with standard error message. I'd like to replace this
    > > message with a prompt that says 'You must select Company first' with an OK
    > > button that then takes them back to the selection box. What's the best (and
    > > easiest) way to do this please.
    > > Thanks - Sheila
     
Since you're here... we have a small favor to ask...

More people are visiting & reading SPN than ever but far fewer are paying to sustain it. Advertising revenues across the online media have fallen fast. So you can see why we need to ask for your help. Donating to SPN's is vote for free speech, for diversity of opinions, for the right of the people to stand up to religious bigotry. Without any affiliation to any organization, this constant struggle takes a lot of hard work to sustain as we entirely depend on the contributions of our esteemed writers/readers. We do it because we believe our perspective matters – because it might well be your perspective, too... Fund our efforts and together we can keep the world informed about the real Sikh Sikhi Sikhism. If everyone who writes or reads our content, who likes it, helps us to pay for it, our future would be much more secure. Every Contribution Matters, Contribute Generously!

    Become a Supporter      ::     Make a Contribution     



Share This Page