Welcome to SPN

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

Sign Up Now!

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
     

Share This Page