|
-
May 27th, 2005, 07:45 AM
#1
Thread Starter
Hyperactive Member
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:
Private Sub Contacts()
Dim sSQL As String
Dim strContacts As String
Set cnContacts = New ADODB.Connection 'we've declared it as a ADODB connection lets set it.
cnContacts.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= C:\New Folder\Quote1.mdb" 'this is the connection string explained in the notes section.
cnContacts.Open
Set rsContacts = New ADODB.Recordset 'as we did with the connection
strContacts = frmCustomers.txtAddress1.Text
'Below is the SQL Statement to gather the correct information
'from tblContact and tblCustomer.
sSQL = "SELECT "
sSQL = sSQL & "Contact1 "
sSQL = sSQL & "FROM "
sSQL = sSQL & "tblContact "
sSQL = sSQL & "WHERE Address "
sSQL = sSQL & "= '" & strContacts & "' "
rsContacts.Open sSQL, cnContacts, adOpenDynamic, adLockOptimistic, adCmdText
Set DataGrid1.DataSource = rsContacts.DataSource
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
-
May 27th, 2005, 09:39 AM
#2
Thread Starter
Hyperactive Member
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
-
May 31st, 2005, 07:17 AM
#3
Thread Starter
Hyperactive Member
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
-
May 31st, 2005, 07:36 AM
#4
Re: Adodb and datagrid
 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?
-
May 31st, 2005, 07:39 AM
#5
Thread Starter
Hyperactive Member
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
-
Jun 1st, 2005, 06:57 AM
#6
Thread Starter
Hyperactive Member
Re: Adodb and datagrid
I just tried adding the following, and it still didn't work.
VB Code:
Private Sub DataGrid1_AfterUpdate()
rsCustomer.Fields("Address") = txtAddress1.Text & ""
rsCustomer.Save
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|