Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    accessprogram is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2010
    Posts
    14

    FORM Fields Programming

    Hi All,

    Merry Christmas. I am having a problem with vba code in access form. I

    am trying to autopoulate fields on form from the table in access. I have code that is running good for the selected table I mention in my code given below


    Private Sub Form_Load()
    Dim con As ADODB.Connection
    Dim rst As New ADODB.Recordset
    Dim sSQL As String

    sSQL = "SELECT * FROM client"

    Set con = CurrentProject.Connection
    rst.Open sSQL, con

    Do While Not rst.EOF
    Me.label1 = rst.Fields(0).Name
    Me.label2 = rst.Fields(1).Name


    Exit Do

    Loop
    rst.Close
    con.Close
    Set rst = Nothing
    Set con = Nothing

    End Sub

    The table mentioned is Client and the form fields will populate all the columns of this table only. now I want the form to auto populate fields from the table that I select in the database, inshort I want to keep table selection part in the code dynamic. PLEASE HELP.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Does that actually work when there are multiple records in client? To answer your question, this type of thing:

    sSQL = "SELECT * FROM " & Forms!FormName.TextboxContainingTableName
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    accessprogram is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2010
    Posts
    14

    Forms Programming

    Hi All,

    I am having a problem with vba code in access form. I

    am trying to autopoulate fields on form from the table in access. I have code that is running good for the selected table I mention in my code given below


    Private Sub Form_Load()
    Dim con As ADODB.Connection
    Dim rst As New ADODB.Recordset
    Dim sSQL As String

    sSQL = "SELECT * FROM client"

    Set con = CurrentProject.Connection
    rst.Open sSQL, con

    Do While Not rst.EOF
    Me.label1 = rst.Fields(0).Name
    Me.label2 = rst.Fields(1).Name
    Exit Do

    Loop
    rst.Close
    con.Close
    Set rst = Nothing
    Set con = Nothing

    End Sub

    The table mentioned is Client and the form fields will populate all the columns of this table only. now I want the form to auto populate fields from the table that I select in the database, inshort I want to keep table selection part(sSQL = "SELECT * FROM client) in the code dynamic. so that when I enter table name in one form textbox it will pass this text to the other form code on load and place it in the ssql statement table place in place of client. PLEASE HELP.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    This would appear to be a duplicate of this thread:

    https://www.accessforums.net/program...ing-10121.html
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    accessprogram is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2010
    Posts
    14

    Reply

    Quote Originally Posted by pbaldy View Post
    This would appear to be a duplicate of this thread:

    https://www.accessforums.net/program...ing-10121.html

    Hello Pbaldy, Yes the thread is again posted by me, actually the solution that you gave is not running and so I wanted to get help regarding that. Please help with the solution. I appreciate for your reply and solution. Thanks.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Why didn't you post a follow-up question there? How is it "not running"? What exactly is your setup, as what I posted should work perfectly given what you described.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    accessprogram is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2010
    Posts
    14

    Access Help

    I am new to this forum, so if there is any mistake on my part I apologize for that. secondly your syntax for the code is actually not recognizing and giving the error as I am trying to put it in

    sSQL= select * from "& Forms!form2!txttbl

    like this. I have xp set up and 2007 access database file. Plz help. let me

    knw if you can join teamviewer presentation. your help is very important for me and I want to learn vba coding skills from you. Thanks for your kind
    gesture. I look forward for you reply.

    Karan

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You missed the opening quotes; try

    sSQL= "select * from " & Forms!form2!txttbl
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    accessprogram is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2010
    Posts
    14
    Quote Originally Posted by pbaldy View Post
    You missed the opening quotes; try

    sSQL= "select * from " & Forms!form2!txttbl


    Hello PBaldy,

    Thanks for the help. I tried this syntax its not giving any error message but at the same time its not taking the table name from form 2. Is there any part to be added at sSQL= "select * from " & Forms!form2!txttbl

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    That looks okay; the textbox contains a table name? Do you know how to set a breakpoint and examine what's being returned as the code runs, or can you post the db? More info on the breakpoint here:

    http://www.baldyweb.com/Debugging.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    accessprogram is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2010
    Posts
    14
    Quote Originally Posted by pbaldy View Post
    That looks okay; the textbox contains a table name? Do you know how to set a breakpoint and examine what's being returned as the code runs, or can you post the db? More info on the breakpoint here:

    http://www.baldyweb.com/Debugging.htm

    Hello,

    I tried to put the sSQL = "SELECT * FROM " & Forms!form2!txt1
    in immediate window and it gives the result (False)

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    That wouldn't really accomplish anything in the immediate window; this would tell you what's in the form:

    ?Forms!form2!txt1

    Add this line after that one:

    Debug.Print sSQL

    That will print the finished SQL string out to the Immediate window.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    accessprogram is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2010
    Posts
    14
    Quote Originally Posted by pbaldy View Post
    That wouldn't really accomplish anything in the immediate window; this would tell you what's in the form:

    ?Forms!form2!txt1

    Add this line after that one:

    Debug.Print sSQL

    That will print the finished SQL string out to the Immediate window.

    Hello,

    Sorry I couldn't understood the last reply, I placed the debug.print sSQL after the sSQL statement but it gives nothing and I am not sure what exactly to do in immediate window.

  14. #14
    accessprogram is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2010
    Posts
    14
    Quote Originally Posted by accessprogram View Post
    Hello,

    Sorry I couldn't understood the last reply, I placed the debug.print sSQL after the sSQL statement but it gives nothing and I am not sure what exactly to do in immediate window.

    It gives me the error microsoft office cant find the form2 referred to in visual basic or macro expression

    sSQL = "SELECT * FROM " & Forms!form2!txt1
    Debug.Print sSQL

  15. #15
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Can you post the db?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Inputbox on programming? :(
    By radicrains in forum Programming
    Replies: 7
    Last Post: 11-05-2010, 10:58 PM
  2. Is my programming wrong? :(
    By radicrains in forum Programming
    Replies: 5
    Last Post: 10-27-2010, 08:39 PM
  3. 2 programming issues
    By gripper in forum Programming
    Replies: 3
    Last Post: 10-06-2010, 11:10 AM
  4. programming a continuous form?
    By Ferret in forum Programming
    Replies: 3
    Last Post: 05-30-2010, 04:51 PM
  5. VB Programming
    By mstefansen in forum Programming
    Replies: 4
    Last Post: 08-31-2009, 07:15 AM

Tags for this Thread

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