Form Navigation

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,
 
N

Nikos Yannacopoulos

Pat,

I suspect the error comes from the seconr recordset SQL statement:
strSQL = "SELECT * FROM [LU_Forms] WHERE [FormOrder] = " & intOrder & ""

intOrder being numeric, there should be no trailing quotes:

strSQL = "SELECT * FROM [LU_Forms] WHERE [FormOrder] = " & intOrder

Apart from that, it's good practice to close resordsets when done with
them, and reset (Set xxx = Nothing) both recordsets and database
objects. That said, using reocrdset operations for this is kind of an
overkill. Try this instead:

Sub OpenNextForm(strName As String)
Dim intOrder As Integer, frmName As String

On Error GoTo OpenNextForm_Err

intOrder = DLookup("[FormOrder]","LU_Forms", "[FormName]='" &
strName & "'"
frmName = DLookup("[FormName]","LU_Forms", "[FormOrder]=" &
intOrder + 1
If Not IsNull(frmName) Then
DoCmd.OpenForm frmName, , , , acAdd
End If
DoCmd.Close acForm, strName
OpenNextForm_Err:
MsgBox Err.Description
Resume Next

End Sub

(watch out for wrapping in the newsreader; the DLookups should be in one
line).

HTH,
Nikos


Pat said:
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,
 
P

Pat Dools

Hi Nikos,

I'm close to getting your suggested code to work. However, I keep getting
the error "Syntax error in string in query expression
'[FormName]=FEligCriteria'."

Here is the Module that I execute on the 'On Click' Event Procedure of a
Command Button on the initial form in the database (i.e., the FormName
('FEligCriteria') that has a FormOrder value of 0 (zero) in my 'LU_Forms'
table):

Option Compare Database
Option Explicit

Sub OpenNextForm(strName As String)
Dim intOrder As Integer, frmName As String

On Error GoTo OpenNextForm_Err

intOrder = DLookup("[FormOrder]", "LU_Forms", "[FormName]= '" & strName
& "")
frmName = DLookup("[FormName]", "LU_Forms", "[FormOrder]= " & intOrder
+ 1)
If Not IsNull(frmName) Then
DoCmd.OpenForm frmName, , , , acAdd
End If
DoCmd.Close acForm, strName
OpenNextForm_Err:
MsgBox Err.Description
Resume Next

End Sub

Also, when I execute the code on the initial form ('FEligCriteria'), I get
the above error message, but it actually does close the 'FEligCriteria' form
and open the next form ('FDemographics') which has a FormOrder Value of 1
(one). However, when I put another Command Button onto this form
'FDemographics' to execute the above code, I get the error "Syntax error in
string in query expression '[FormName]=FDemogrphics'.", and instead of
opening the next form according to the table 'LU_Forms' (i.e., the form with
a FormOrder value of 2 (two), it simply closes the 'FDemographics' form
altogether. Very strange, but I've made some progress from my initial
attempts. What is the syntax error being referenced here and how do I fix
it? I've tried every little tweak of single quotes, double quotes, etc. I
could think of.

Thanks,

Nikos Yannacopoulos said:
Pat,

I suspect the error comes from the seconr recordset SQL statement:
strSQL = "SELECT * FROM [LU_Forms] WHERE [FormOrder] = " & intOrder & ""

intOrder being numeric, there should be no trailing quotes:

strSQL = "SELECT * FROM [LU_Forms] WHERE [FormOrder] = " & intOrder

Apart from that, it's good practice to close resordsets when done with
them, and reset (Set xxx = Nothing) both recordsets and database
objects. That said, using reocrdset operations for this is kind of an
overkill. Try this instead:

Sub OpenNextForm(strName As String)
Dim intOrder As Integer, frmName As String

On Error GoTo OpenNextForm_Err

intOrder = DLookup("[FormOrder]","LU_Forms", "[FormName]='" &
strName & "'"
frmName = DLookup("[FormName]","LU_Forms", "[FormOrder]=" &
intOrder + 1
If Not IsNull(frmName) Then
DoCmd.OpenForm frmName, , , , acAdd
End If
DoCmd.Close acForm, strName
OpenNextForm_Err:
MsgBox Err.Description
Resume Next

End Sub

(watch out for wrapping in the newsreader; the DLookups should be in one
line).

HTH,
Nikos


Pat said:
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,
 
N

Nikos Yannacopoulos

Pat,

I think the problem is you've missed a single quote between the double
ones at the end of the intOrder DLookup. The line of code should be:

intOrder = DLookup("[FormOrder]", "LU_Forms", "[FormName]= '" & strName
& "'")

(watch out for wrapping in the newsreader!)

General tip: when trying to debug code, temporarily disable error
handling by commenting it out.

HTH,
Nikos

Pat said:
Hi Nikos,

I'm close to getting your suggested code to work. However, I keep getting
the error "Syntax error in string in query expression
'[FormName]=FEligCriteria'."

Here is the Module that I execute on the 'On Click' Event Procedure of a
Command Button on the initial form in the database (i.e., the FormName
('FEligCriteria') that has a FormOrder value of 0 (zero) in my 'LU_Forms'
table):

Option Compare Database
Option Explicit

Sub OpenNextForm(strName As String)
Dim intOrder As Integer, frmName As String

On Error GoTo OpenNextForm_Err

intOrder = DLookup("[FormOrder]", "LU_Forms", "[FormName]= '" & strName
& "")
frmName = DLookup("[FormName]", "LU_Forms", "[FormOrder]= " & intOrder
+ 1)
If Not IsNull(frmName) Then
DoCmd.OpenForm frmName, , , , acAdd
End If
DoCmd.Close acForm, strName
OpenNextForm_Err:
MsgBox Err.Description
Resume Next

End Sub

Also, when I execute the code on the initial form ('FEligCriteria'), I get
the above error message, but it actually does close the 'FEligCriteria' form
and open the next form ('FDemographics') which has a FormOrder Value of 1
(one). However, when I put another Command Button onto this form
'FDemographics' to execute the above code, I get the error "Syntax error in
string in query expression '[FormName]=FDemogrphics'.", and instead of
opening the next form according to the table 'LU_Forms' (i.e., the form with
a FormOrder value of 2 (two), it simply closes the 'FDemographics' form
altogether. Very strange, but I've made some progress from my initial
attempts. What is the syntax error being referenced here and how do I fix
it? I've tried every little tweak of single quotes, double quotes, etc. I
could think of.

Thanks,

:

Pat,

I suspect the error comes from the seconr recordset SQL statement:
strSQL = "SELECT * FROM [LU_Forms] WHERE [FormOrder] = " & intOrder & ""

intOrder being numeric, there should be no trailing quotes:

strSQL = "SELECT * FROM [LU_Forms] WHERE [FormOrder] = " & intOrder

Apart from that, it's good practice to close resordsets when done with
them, and reset (Set xxx = Nothing) both recordsets and database
objects. That said, using reocrdset operations for this is kind of an
overkill. Try this instead:

Sub OpenNextForm(strName As String)
Dim intOrder As Integer, frmName As String

On Error GoTo OpenNextForm_Err

intOrder = DLookup("[FormOrder]","LU_Forms", "[FormName]='" &
strName & "'"
frmName = DLookup("[FormName]","LU_Forms", "[FormOrder]=" &
intOrder + 1
If Not IsNull(frmName) Then
DoCmd.OpenForm frmName, , , , acAdd
End If
DoCmd.Close acForm, strName
OpenNextForm_Err:
MsgBox Err.Description
Resume Next

End Sub

(watch out for wrapping in the newsreader; the DLookups should be in one
line).

HTH,
Nikos


Pat said:
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,
 
P

Pat Dools

A BIG thank you!! I had actually tried that and had forgotten that I was
receiving an 'Invalid use of Null' error message (but it would still navigate
to the next form anyway). Once I changed the 'FormOrder' value of the first
form in the series from '0' to '1', the form navigation works without error.
Thank you again!

Patrick

Nikos Yannacopoulos said:
Pat,

I think the problem is you've missed a single quote between the double
ones at the end of the intOrder DLookup. The line of code should be:

intOrder = DLookup("[FormOrder]", "LU_Forms", "[FormName]= '" & strName
& "'")

(watch out for wrapping in the newsreader!)

General tip: when trying to debug code, temporarily disable error
handling by commenting it out.

HTH,
Nikos

Pat said:
Hi Nikos,

I'm close to getting your suggested code to work. However, I keep getting
the error "Syntax error in string in query expression
'[FormName]=FEligCriteria'."

Here is the Module that I execute on the 'On Click' Event Procedure of a
Command Button on the initial form in the database (i.e., the FormName
('FEligCriteria') that has a FormOrder value of 0 (zero) in my 'LU_Forms'
table):

Option Compare Database
Option Explicit

Sub OpenNextForm(strName As String)
Dim intOrder As Integer, frmName As String

On Error GoTo OpenNextForm_Err

intOrder = DLookup("[FormOrder]", "LU_Forms", "[FormName]= '" & strName
& "")
frmName = DLookup("[FormName]", "LU_Forms", "[FormOrder]= " & intOrder
+ 1)
If Not IsNull(frmName) Then
DoCmd.OpenForm frmName, , , , acAdd
End If
DoCmd.Close acForm, strName
OpenNextForm_Err:
MsgBox Err.Description
Resume Next

End Sub

Also, when I execute the code on the initial form ('FEligCriteria'), I get
the above error message, but it actually does close the 'FEligCriteria' form
and open the next form ('FDemographics') which has a FormOrder Value of 1
(one). However, when I put another Command Button onto this form
'FDemographics' to execute the above code, I get the error "Syntax error in
string in query expression '[FormName]=FDemogrphics'.", and instead of
opening the next form according to the table 'LU_Forms' (i.e., the form with
a FormOrder value of 2 (two), it simply closes the 'FDemographics' form
altogether. Very strange, but I've made some progress from my initial
attempts. What is the syntax error being referenced here and how do I fix
it? I've tried every little tweak of single quotes, double quotes, etc. I
could think of.

Thanks,

:

Pat,

I suspect the error comes from the seconr recordset SQL statement:
strSQL = "SELECT * FROM [LU_Forms] WHERE [FormOrder] = " & intOrder & ""

intOrder being numeric, there should be no trailing quotes:

strSQL = "SELECT * FROM [LU_Forms] WHERE [FormOrder] = " & intOrder

Apart from that, it's good practice to close resordsets when done with
them, and reset (Set xxx = Nothing) both recordsets and database
objects. That said, using reocrdset operations for this is kind of an
overkill. Try this instead:

Sub OpenNextForm(strName As String)
Dim intOrder As Integer, frmName As String

On Error GoTo OpenNextForm_Err

intOrder = DLookup("[FormOrder]","LU_Forms", "[FormName]='" &
strName & "'"
frmName = DLookup("[FormName]","LU_Forms", "[FormOrder]=" &
intOrder + 1
If Not IsNull(frmName) Then
DoCmd.OpenForm frmName, , , , acAdd
End If
DoCmd.Close acForm, strName
OpenNextForm_Err:
MsgBox Err.Description
Resume Next

End Sub

(watch out for wrapping in the newsreader; the DLookups should be in one
line).

HTH,
Nikos


Pat Dools wrote:

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,
 
N

Nikos Yannacopoulos

Good! Glad to have helped.

Nikos

Pat said:
A BIG thank you!! I had actually tried that and had forgotten that I was
receiving an 'Invalid use of Null' error message (but it would still navigate
to the next form anyway). Once I changed the 'FormOrder' value of the first
form in the series from '0' to '1', the form navigation works without error.
Thank you again!

Patrick

:

Pat,

I think the problem is you've missed a single quote between the double
ones at the end of the intOrder DLookup. The line of code should be:

intOrder = DLookup("[FormOrder]", "LU_Forms", "[FormName]= '" & strName
& "'")

(watch out for wrapping in the newsreader!)

General tip: when trying to debug code, temporarily disable error
handling by commenting it out.

HTH,
Nikos

Pat said:
Hi Nikos,

I'm close to getting your suggested code to work. However, I keep getting
the error "Syntax error in string in query expression
'[FormName]=FEligCriteria'."

Here is the Module that I execute on the 'On Click' Event Procedure of a
Command Button on the initial form in the database (i.e., the FormName
('FEligCriteria') that has a FormOrder value of 0 (zero) in my 'LU_Forms'
table):

Option Compare Database
Option Explicit

Sub OpenNextForm(strName As String)
Dim intOrder As Integer, frmName As String

On Error GoTo OpenNextForm_Err

intOrder = DLookup("[FormOrder]", "LU_Forms", "[FormName]= '" & strName
& "")
frmName = DLookup("[FormName]", "LU_Forms", "[FormOrder]= " & intOrder
+ 1)
If Not IsNull(frmName) Then
DoCmd.OpenForm frmName, , , , acAdd
End If
DoCmd.Close acForm, strName
OpenNextForm_Err:
MsgBox Err.Description
Resume Next

End Sub

Also, when I execute the code on the initial form ('FEligCriteria'), I get
the above error message, but it actually does close the 'FEligCriteria' form
and open the next form ('FDemographics') which has a FormOrder Value of 1
(one). However, when I put another Command Button onto this form
'FDemographics' to execute the above code, I get the error "Syntax error in
string in query expression '[FormName]=FDemogrphics'.", and instead of
opening the next form according to the table 'LU_Forms' (i.e., the form with
a FormOrder value of 2 (two), it simply closes the 'FDemographics' form
altogether. Very strange, but I've made some progress from my initial
attempts. What is the syntax error being referenced here and how do I fix
it? I've tried every little tweak of single quotes, double quotes, etc. I
could think of.

Thanks,

:



Pat,

I suspect the error comes from the seconr recordset SQL statement:
strSQL = "SELECT * FROM [LU_Forms] WHERE [FormOrder] = " & intOrder & ""

intOrder being numeric, there should be no trailing quotes:

strSQL = "SELECT * FROM [LU_Forms] WHERE [FormOrder] = " & intOrder

Apart from that, it's good practice to close resordsets when done with
them, and reset (Set xxx = Nothing) both recordsets and database
objects. That said, using reocrdset operations for this is kind of an
overkill. Try this instead:

Sub OpenNextForm(strName As String)
Dim intOrder As Integer, frmName As String

On Error GoTo OpenNextForm_Err

intOrder = DLookup("[FormOrder]","LU_Forms", "[FormName]='" &
strName & "'"
frmName = DLookup("[FormName]","LU_Forms", "[FormOrder]=" &
intOrder + 1
If Not IsNull(frmName) Then
DoCmd.OpenForm frmName, , , , acAdd
End If
DoCmd.Close acForm, strName
OpenNextForm_Err:
MsgBox Err.Description
Resume Next

End Sub

(watch out for wrapping in the newsreader; the DLookups should be in one
line).

HTH,
Nikos


Pat Dools wrote:


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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top