Open a form from a field in a specific table (1 Viewer)

toumack

Registered User.
Local time
Today, 05:48
Joined
May 14, 2011
Messages
13
I have a table named "JewelryStyles" in that table I have 2 text field that contains names of form I want to open using VBA at a specific point, in my recordset, I have the name of form, so what should be the command to open that form from an rst?

Image:



Here is the code so far:
Code:
Private Sub STYID1_Click()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Set dbs = CurrentDb
Dim strSQL1 As String
strSQL1 = "SELECT JewelryStyles.StylesID, JewelryStyles.JewelryStyles, JewelryStyles.Styles, JewelryStyles.OrdreTri, JewelryStyles.FormForSizes, JewelryStyles.FormForColors  FROM JewelryStyles WHERE JewelryStyles.OrdreTri=1 ORDER BY JewelryStyles.OrdreTri"
Set rst = CurrentDb.OpenRecordset(strSQL1, dbOpenDynaset, dbSeeChanges)

Me.StyleCode = rst![JewelryStyles]

rst.Close
dbs.Close
Set rst = Nothing
Set dbs = Nothing

DoCmd.OpenForm rst!FormForSizes
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:48
Joined
May 7, 2009
Messages
19,169
Private Sub STYID1_Click()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Set dbs = CurrentDb
Dim strSQL1 As String

Dim strForm As String
strSQL1 = "SELECT JewelryStyles.StylesID, JewelryStyles.JewelryStyles, JewelryStyles.Styles, JewelryStyles.OrdreTri, JewelryStyles.FormForSizes, JewelryStyles.FormForColors FROM JewelryStyles WHERE JewelryStyles.OrdreTri=1 ORDER BY JewelryStyles.OrdreTri"
Set rst = CurrentDb.OpenRecordset(strSQL1, dbOpenDynaset, dbSeeChanges)

Me.StyleCode = rst![JewelryStyles]
strForm=rst!FormForSizes & ""
rst.Close
dbs.Close
Set rst = Nothing
Set dbs = Nothing

if strForm <> "" Then
DoCmd.OpenForm strForm
End If
 

toumack

Registered User.
Local time
Today, 05:48
Joined
May 14, 2011
Messages
13
Thanks, your code will be useful if there is no name in the table for the form size, than continue with the color form.
Super!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:48
Joined
May 7, 2009
Messages
19,169
you mean if the field FormForSizes is blank, use the field FormForColors?



strForm=rst!FormForSizes & ""
if strForm = "" then strForm = rst!FormForColors & ""
rst.Close
dbs.Close
...
 

toumack

Registered User.
Local time
Today, 05:48
Joined
May 14, 2011
Messages
13
I will test it tomorrow, it is 5 o'clock in the morning here… thanks again

Claude
 

Users who are viewing this thread

Top Bottom