Results 1 to 3 of 3
  1. #1
    ramimarachli is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2010
    Posts
    9

    Unhappy Change Record Source of a form to base it on certain table

    I have a form (Form1) with one field (text box "N1")
    on this form I have a button with on click action related to (text box "Text2")
    when clicking the button a table with a name entered in the text box is created.
    this is the vb code used to create the said table:
    Private Sub Command0_Click()
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim tdfNew As TableDef
    Dim fldNew As Field

    '--- set a reference to the database
    Set db = CurrentDb

    '--- create the table

    Set tdfNew = db.CreateTableDef(Text2)

    '--- add integer field
    Set fldNew = tdfNew.CreateField("ClientID", dbInteger)
    '--- save the new field
    tdfNew.Fields.Append fldNew

    '--- add text field (length 20)
    Set fldNew = tdfNew.CreateField("ClientName", dbText, 20)
    '--- save the new field
    tdfNew.Fields.Append fldNew

    '--- save the new table design
    db.TableDefs.Append tdfNew



    '---Initialize your recordset
    Set rs = CurrentDb.OpenRecordset(Text2, dbOpenDynaset)
    ' Add New Record
    '--- Clear memory
    Set fldNew = Nothing
    Set tblNew = Nothing
    Set db = Nothing

    End Sub

    My problem starts when I try to related Form1 to the table created

    i.e. to the table which takes its name from the text box Text2

    any clew

    thanks in advance

  2. #2
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,044
    Hi,

    try:

    Forms("form1").recordsource = me.N1

    greetings
    NG

  3. #3
    ramimarachli is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2010
    Posts
    9
    Quote Originally Posted by NoellaG View Post
    Hi,

    try:

    Forms("form1").recordsource = me.N1

    greetings
    NG
    Thank you NoellaG,

    I've tried you suggestion and before that tried

    Forms("form1").RecordSource = Text2
    Forms("form1").N1.ControlSource = N1
    Forms("form1").N2.ControlSource = N2

    but both do not work and the RecordSource refusing to be changed and stays blank any more ideas

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Form not displaying source table data
    By Sarge, USMC in forum Forms
    Replies: 6
    Last Post: 10-25-2010, 07:36 AM
  2. change print preview record source
    By alaric01 in forum Reports
    Replies: 10
    Last Post: 10-07-2010, 09:51 AM
  3. Replies: 1
    Last Post: 07-04-2010, 03:31 PM
  4. Replies: 3
    Last Post: 02-19-2010, 04:19 PM
  5. Changing the record source in a form
    By lmichaud in forum Forms
    Replies: 1
    Last Post: 07-09-2006, 09:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums