Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing Recordset on created form 1

Status
Not open for further replies.

munger

Programmer
Feb 28, 2001
23
IL
I need to create a form exactly like one already in the database and then give it a new recordsource. The objects appear in the database window but access refuses to
change the recordsource. What is missing? Here is the code.

Feel free to change anything!

Thank you.

Function NewFuturesForm()
Dim dbsMoadon As Database
Dim frm As Form
Dim tbldefNew As TableDef

Set dbsMoadon = CurrentDb

' Make new table called "tblFutures1999" This part works fine!

Set tbldefNew = CurrentDb.CreateTableDef("tblFutures1999")
With tbldefNew
.Fields.Append .CreateField("Certificate", dbInteger, 10)
.Fields.Append .CreateField("FullName", dbText, 50)
.Fields.Append .CreateField("Address", dbText, 50)
.Fields.Append .CreateField("City", dbText, 10)
.Fields.Append .CreateField("PostalCode", dbText, 5)
.Fields.Append .CreateField("Phone", dbText, 10)
.Fields.Append .CreateField("CellPhone", dbText, 10)
End With

dbsMoadon.TableDefs.Append tbldefNew
dbsMoadon.TableDefs.Refresh

' Make new form exactly like the existing form "Futures1998" This part also works!

DoCmd.CopyObject , "frmFutures1999", acForm, "Futures1998"
RefreshDatabaseWindow ' Do I really need this command?

'??????MY PROBLEM??????:
' I now need to change the record source of frmFutures1999
' that it should be "tblFutures1999" I don't know how to do
' this. You will note that I declared frm as a form at the
' beginning but I didn't use frm because I didn't know how
' to "set" it.

Set dbsMoadon = Nothing
End Function
 
perhaps as the following ..:

Function NewFuturesForm()
Dim dbsMoadon As Database
Dim frm As Form
Dim tbldefNew As TableDef

Set dbsMoadon = CurrentDb

' Make new table called "tblFutures1999" This part works fine!

Set tbldefNew = CurrentDb.CreateTableDef("tblFutures1999")
With tbldefNew
.Fields.Append .CreateField("Certificate", dbInteger, 10)
.Fields.Append .CreateField("FullName", dbText, 50)
.Fields.Append .CreateField("Address", dbText, 50)
.Fields.Append .CreateField("City", dbText, 10)
.Fields.Append .CreateField("PostalCode", dbText, 5)
.Fields.Append .CreateField("Phone", dbText, 10)
.Fields.Append .CreateField("CellPhone", dbText, 10)
End With

dbsMoadon.TableDefs.Append tbldefNew
dbsMoadon.TableDefs.Refresh


' Make new form exactly like the existing form "Futures1998" This part also works!
DoCmd.CopyObject , "frmFutures1999", acForm, "Futures1998"

DoCmd.OpenForm "frmFutures1999", acDesign, , , acFormEdit, acHidden
Set frm = Forms!MainFormNew

frm.RecordSource = "SELECT * FROM tblFutures1999"

'...... >>>> ...

Set rst = Nothing
Set dbsMoadon = Nothing

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top