Results 1 to 6 of 6

Thread: Adodb and datagrid

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2003
    Posts
    419

    Post Adodb and datagrid

    Hello, for some reason ever since I started changing from bound controls to code for ADO connections, simple things are becoming more complicated. I have a datagrid on a form, that I want to fill. I want it to fill from Quote1.mdb, tblContact.Contact1. But, I only want it to add contacts that match the displayed address in a textbox. This should be easy, I always get an error saying something isn't BookMarkable.
    Below, is the connection code:

    VB Code:
    1. Private Sub Contacts()
    2.  
    3. Dim sSQL As String
    4. Dim strContacts As String
    5.        
    6. Set cnContacts = New ADODB.Connection 'we've declared it as a ADODB connection lets set it.
    7.     cnContacts.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    8.     "Data Source= C:\New Folder\Quote1.mdb" 'this is the connection string explained in the notes section.
    9.     cnContacts.Open
    10. Set rsContacts = New ADODB.Recordset 'as we did with the connection
    11.    
    12. strContacts = frmCustomers.txtAddress1.Text
    13.  
    14.     'Below is the SQL Statement to gather the correct information
    15.     'from tblContact and tblCustomer.
    16.     sSQL = "SELECT "
    17.     sSQL = sSQL & "Contact1 "
    18.     sSQL = sSQL & "FROM  "
    19.     sSQL = sSQL & "tblContact "
    20.     sSQL = sSQL & "WHERE Address "
    21.     sSQL = sSQL & "= '" & strContacts & "' "
    22.  
    23.     rsContacts.Open sSQL, cnContacts, adOpenDynamic, adLockOptimistic, adCmdText
    24. Set DataGrid1.DataSource = rsContacts.DataSource
    25. End Sub

    Also, is datagrid the right control I should use if I also want to add data to the tbl by typing in the datagrid?
    Last edited by LostAngel; May 27th, 2005 at 09:48 AM.
    Code:
    If LostAngel.Tag = "Programming" then
       LostAngel.Caption = "Awake"
    Else
       LostAngel.Caption = "Dreaming of Code"
    End If

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2003
    Posts
    419

    Re: Adodb and datagrid

    **RESOLVED**
    I found what I was looking for here:
    http://www.vbforums.com/showthread.php?t=321471

    But, I found one problem. It allows me to add a new contact via the DataGrid by supplying a blank row under the listed contacts. The problem is, how can I have it automatically When I type "Bill Smith" for example, also set the Address for Bill Smith as the same address of all of the Contacts for whatever company he's in? If it helps, the address needed is also located in a textbox on screen.
    Last edited by LostAngel; May 27th, 2005 at 09:51 AM.
    Code:
    If LostAngel.Tag = "Programming" then
       LostAngel.Caption = "Awake"
    Else
       LostAngel.Caption = "Dreaming of Code"
    End If

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2003
    Posts
    419

    Re: Adodb and datagrid

    I don't want to litter vbforums with a new post, so i'll just bump this.

    When I goto add a contact in to a customer (company) via the datagrid, I have to manually type in an address as well. Is there a way that I can have it automatically save the value in txtAddress1 to the new contact I add?
    Code:
    If LostAngel.Tag = "Programming" then
       LostAngel.Caption = "Awake"
    Else
       LostAngel.Caption = "Dreaming of Code"
    End If

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Adodb and datagrid

    Quote Originally Posted by LostAngel
    I don't want to litter vbforums with a new post, so i'll just bump this.

    When I goto add a contact in to a customer (company) via the datagrid, I have to manually type in an address as well. Is there a way that I can have it automatically save the value in txtAddress1 to the new contact I add?
    Do you want the value in txtAddress1 written back to your contacts table?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2003
    Posts
    419

    Re: Adodb and datagrid

    Yes, The setup of the form has textboxes. These textboxes have CustomerName, Address1, Address2, City, State, Zip. It also has a datagrid which lists contacts for each company. When I add a Contact, I want it to automatically fill in whatever txtAddress1.Text is into the Address1 field for the Contact Name I just added. (I.E.: If I add "John Smith", I want txtAddress1.Text to automatically goto the tblContact.Address1 for "John Smith"s row.
    Code:
    If LostAngel.Tag = "Programming" then
       LostAngel.Caption = "Awake"
    Else
       LostAngel.Caption = "Dreaming of Code"
    End If

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2003
    Posts
    419

    Re: Adodb and datagrid

    I just tried adding the following, and it still didn't work.

    VB Code:
    1. Private Sub DataGrid1_AfterUpdate()
    2.     rsCustomer.Fields("Address") = txtAddress1.Text & ""
    3.     rsCustomer.Save
    4. End Sub
    Code:
    If LostAngel.Tag = "Programming" then
       LostAngel.Caption = "Awake"
    Else
       LostAngel.Caption = "Dreaming of Code"
    End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width