P
Pat Dools
Hello,
I am using MS Access 2003. I am trying to get a couple of pieces of code to
work such that I click on a 'Next' Command Button on a form and it
automatically closes the active form and opens the next form based on values
in a table ('LU_Forms', in this example) which contains 'FormName' and
'FormNumber' fields. The 'Next' Command Button executes thie Event Procedure
(On Click):
Private Sub Next_Click()
On Error GoTo Err_Next_Click
Call OpenNextForm(Me.Name)
Exit_Next_Click:
Exit Sub
Err_Next_Click:
DoCmd.Close acForm, Me.Name
Resume Exit_Next_Click
End Sub
which then executes this code inside a Module:
Option Compare Database
Option Explicit
' Opens next Screening Form based on next form number as assigned in Table
'LU_Forms'
Sub OpenNextForm(strName As String)
On Error GoTo OpenNextForm_Err
Dim strSQL As String, intOrder As Integer, rst As Recordset, dbs As Database
Set dbs = CurrentDb
strSQL = "SELECT * FROM [LU_Forms] WHERE [FormName] = """ & strName & """"
Set rst = dbs.OpenRecordset(strSQL)
intOrder = rst![FormOrder] + 1
strSQL = "SELECT * FROM [LU_Forms] WHERE [FormOrder] = " & intOrder & ""
Set rst = dbs.OpenRecordset(strSQL)
' If Not IsNull(rst![FormName]) Then
DoCmd.OpenForm rst![FormName], , , , acAdd
' End If
DoCmd.Close acForm, strName
' Call SetAutoValues(Forms(rst![FormName]))
OpenNextForm_Err:
MsgBox Err.Description
Resume Next
End Sub
I get this error message when I click on the 'Next' Command Button: 'Type
mismatch: Obj. variable or With block variable not set'. This 'Next' button
is now sitting on the Form I assigned the number 0 (zero), and when I click,
I would like it to open the Form I assigned the number 1. I have ensured
that the 'Microsoft DAO 3.6 Object Library' is checked in the 'References'
dialog. Some of the Forms have names that include spaces in them, could that
be an issue?
Thanks,
I am using MS Access 2003. I am trying to get a couple of pieces of code to
work such that I click on a 'Next' Command Button on a form and it
automatically closes the active form and opens the next form based on values
in a table ('LU_Forms', in this example) which contains 'FormName' and
'FormNumber' fields. The 'Next' Command Button executes thie Event Procedure
(On Click):
Private Sub Next_Click()
On Error GoTo Err_Next_Click
Call OpenNextForm(Me.Name)
Exit_Next_Click:
Exit Sub
Err_Next_Click:
DoCmd.Close acForm, Me.Name
Resume Exit_Next_Click
End Sub
which then executes this code inside a Module:
Option Compare Database
Option Explicit
' Opens next Screening Form based on next form number as assigned in Table
'LU_Forms'
Sub OpenNextForm(strName As String)
On Error GoTo OpenNextForm_Err
Dim strSQL As String, intOrder As Integer, rst As Recordset, dbs As Database
Set dbs = CurrentDb
strSQL = "SELECT * FROM [LU_Forms] WHERE [FormName] = """ & strName & """"
Set rst = dbs.OpenRecordset(strSQL)
intOrder = rst![FormOrder] + 1
strSQL = "SELECT * FROM [LU_Forms] WHERE [FormOrder] = " & intOrder & ""
Set rst = dbs.OpenRecordset(strSQL)
' If Not IsNull(rst![FormName]) Then
DoCmd.OpenForm rst![FormName], , , , acAdd
' End If
DoCmd.Close acForm, strName
' Call SetAutoValues(Forms(rst![FormName]))
OpenNextForm_Err:
MsgBox Err.Description
Resume Next
End Sub
I get this error message when I click on the 'Next' Command Button: 'Type
mismatch: Obj. variable or With block variable not set'. This 'Next' button
is now sitting on the Form I assigned the number 0 (zero), and when I click,
I would like it to open the Form I assigned the number 1. I have ensured
that the 'Microsoft DAO 3.6 Object Library' is checked in the 'References'
dialog. Some of the Forms have names that include spaces in them, could that
be an issue?
Thanks,