Increment form open cbo from unbound table

M

Maarkr

I have twenty forms that need to open and close in order (increment by 1)
using an On_Click event. I added a table named TableOfForms with a FormNo
field (in opening order) and FormName Field. I got the form that is open to
get the current form name and number , but now I can't figure out how to open
the next form number in the TableOfForms...it is not bound to this
form...tried a couple of ways but my little brain is just not getting there
today. Thought I saw a post where you can't open a form from a table?? Do I
have to open a recordset to get the value? I'm not very good at that level
yet. Thanks for any help.

intFormNbr = DLookup("FormNo", "TableOfForms", "Form.Name =[FormName]")
intFormNbr = intFormNbr +1

DoCmd.Open Form "get the formname from tableofforms.column(1) where
intformnbr = tableofforms.column(0) aaaaarrrrggggg!"
 
W

Wolfgang Kais

Hello Maarkr.

Maarkr said:
I have twenty forms that need to open and close in order
(increment by 1) using an On_Click event. I added a table named
TableOfForms with a FormNo field (in opening order) and FormName
Field. I got the form that is open to get the current form name
and number, but now I can't figure out how to open the next form
number in the TableOfForms...it is not bound to this form...tried
a couple of ways but my little brain is just not getting there
today. Thought I saw a post where you can't open a form from a
table?? Do I have to open a recordset to get the value? I'm not
very good at that level yet. Thanks for any help.

intFormNbr = DLookup("FormNo", "TableOfForms", "Form.Name =[FormName]")
intFormNbr = intFormNbr+1

DoCmd.Open Form "get the formname from tableofforms.column(1) where
intformnbr = tableofforms.column(0) aaaaarrrrggggg!"

You could simply get the name of the form with a DLookup:
DLookup("FormName", "TableOfForms", "FormNo=" & intFormNbr)

And of course, you could use a recordset instead:

Dim strSQL as String, strNextForm as String
strSQL = "Select FormName From TableOfForms Order By FormNo"
With CurrentDb.OpenRecordset(strSQL, dbOpenFormwardOnly)
.FindFirst BuildCriteria("FormName", dbText, Me.Name)
If Not .NoMatch Then
.MoveNext
if Not .EOF Then strNextForm = !FormName
End If
.Close
End With
If strNextForm <> vbNullString Then DoCmd.OpenForm strNextForm
 
M

Maarkr

The old "double DLookup" trick. new it wasn't too hard...thanks

Wolfgang Kais said:
Hello Maarkr.

Maarkr said:
I have twenty forms that need to open and close in order
(increment by 1) using an On_Click event. I added a table named
TableOfForms with a FormNo field (in opening order) and FormName
Field. I got the form that is open to get the current form name
and number, but now I can't figure out how to open the next form
number in the TableOfForms...it is not bound to this form...tried
a couple of ways but my little brain is just not getting there
today. Thought I saw a post where you can't open a form from a
table?? Do I have to open a recordset to get the value? I'm not
very good at that level yet. Thanks for any help.

intFormNbr = DLookup("FormNo", "TableOfForms", "Form.Name =[FormName]")
intFormNbr = intFormNbr+1

DoCmd.Open Form "get the formname from tableofforms.column(1) where
intformnbr = tableofforms.column(0) aaaaarrrrggggg!"

You could simply get the name of the form with a DLookup:
DLookup("FormName", "TableOfForms", "FormNo=" & intFormNbr)

And of course, you could use a recordset instead:

Dim strSQL as String, strNextForm as String
strSQL = "Select FormName From TableOfForms Order By FormNo"
With CurrentDb.OpenRecordset(strSQL, dbOpenFormwardOnly)
.FindFirst BuildCriteria("FormName", dbText, Me.Name)
If Not .NoMatch Then
.MoveNext
if Not .EOF Then strNextForm = !FormName
End If
.Close
End With
If strNextForm <> vbNullString Then DoCmd.OpenForm strNextForm
 

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