Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2008
    Location
    All over, Now in Missouri
    Posts
    73

    Unanswered: VBA GoTo Command problem

    I have a form that has a PREVIEW and a PRINT cmd button on it. If the person pressed enter instead of a command button I want them to preview the report. my code

    Private Sub Form_KeyPress(KeyAscii As Integer)

    If KeyAscii = 13 Then
    GoTo cmdpre
    End If
    End Sub


    Private Sub cmdPreview_Click()
    cmdpre:

    On Error GoTo Err_cmdpreview_Click

    If IsNull(cbocla) Then
    MsgBox "You Left the Class Number Field Empty." _
    & vbCrLf & " " _
    & vbCrLf & "Please Try Again.", vbExclamation
    cbocla.SetFocus
    Exit Sub
    End If

    Dim stDocName As String

    stDocName = "rptStudentRosternoSSN"
    DoCmd.OpenReport stDocName, acPreview
    DoCmd.Close acForm, "frmpopclassnum_rosternossn"


    Exit_cmdpreview_Click:
    Exit Sub

    Err_cmdpreview_Click:
    MsgBox Err.Description
    Resume Exit_cmdpreview_Click
    End Sub

  2. #2
    Join Date
    Sep 2002
    Location
    South Wales
    Posts
    580
    Try this;

    Make cmdPreview_Click() PUBLIC
    Call it during the form event:

    Private Sub Form_KeyPress(KeyAscii As Integer)

    If KeyAscii = 13 Then
    Call cmdPreview_Click()

    End If
    End Sub

    Public Sub cmdPreview_Click()
    Windows Server 2003-8 / Terminal Services / SQL 2000 / Access 2003 / Office 2003-7 / Exchange 2003-7 / Blackberry Enterprise Server / AutoCAD / Lambert And Butler / Red Bull

  3. #3
    Join Date
    Sep 2006
    Location
    Surrey, UK
    Posts
    995
    Provided Answers: 2
    Just to confirm, you can't jump between subs using GoTo.

    Also, if both subs are in the same module, you won't need to make the called sub public.

  4. #4
    Join Date
    Apr 2008
    Location
    All over, Now in Missouri
    Posts
    73

    That was easy

    Thanks for the help, works great!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •