|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
How do I ADD to a table from main form?
Hi everyone.
On this 2nd day of snow (ny) I am writing my first question . . I will try to help those, when I can, and if I have an answers to give ![]() I have an access db that has many controls fields on a form. In the db, I have a separate organization table that I keep data in. Table name: tblOrg ie, OrgName; Address; City; St; and Zipcode About 5,300 items and counting (soon as I can figure out how to add to this list separately) I need to know how to add to this table, from my main form, which has those items listed above on the form. Let me explain... Step 1: One of the first things I do when I open my main form, is click on the OrgLookup combo listbox. As I begin typing, the names being to closely match what I'm searching form. If a match is found, I just simply click on it, and the Organizations fields (from tblOrg) is filled in on my forms fields, which works out perfectly, however. Step 2: When I perform the same routine in Step 1: and I do NOT find a match, I then begin to type in "manually" the Organization's name/address data. This is where I need to ADD those manually typed fields, into my tblOrg 's table. HOW ??? . . At the moment, I have a NEW button that I created on my main form. It's basically waiting for the code to add to it I know it's easy, but my last two (500pg) access books didn't cover this (AFAICT) So, here I am, asking for assistance on this. -myaccess |
|
#2
|
|||
|
|||
|
Dim DAOdb As Database
Dim DAOrs As Recordset Dim sSQL As String Set DAOdb = CurrentDb() s = "tblOrg" Set DAOrs = DAOdb.OpenRecordset(s) With DAOrs .AddNew .Fields("OrgName") = Me.cmboOrgName .Fields("Address") = Me.txtAddress .Fields("City") = Me.txtCity .Fields("ST") = Me.txtST .Fields("Zipcode") = Me.txtZipcode .Update End With MsgBox Me.cmboOrgName& " Added" DAOrs.Close DAOdb.Close You will also need to Reference a Microsoft DAO Object Libray S- |
|
#3
|
|||
|
|||
|
sbaxter, thanks for the help
![]() I can see I'm already experiencing problems in the snip you posted ie, MsgBox Me.cmboOrgName& " Added" But, I cought it, the "&" was part of the statement hehe.. But, I DO appreciate your assistance in this and for providing me w/ the code snips to work on. And, that is just what I'm doing. Working on it. I'll get it to work, cause how else will I learn unless I hit up against some bumps. I'll let you know how it comes along. I can't wait to give it a go when it works perfectly. About the code. . . I'm assuming that I need to attatch it to my buttons (called ADD) 's on Click event. So, here I go.. off to have fun. I'll keep you posted of my progress. Thanks again, -myaccess |
|
#4
|
|||
|
|||
|
"I'm assuming that I need to attatch it to my buttons (called ADD) 's on Click event."
Correct Reminder: Add the Reference to the DAO Library S- |
|
#5
|
|||
|
|||
|
@ sbaxter,
ureeka !! I got it working !! But, unfortunately, after lots of trial and error scenes, I left quite a mess of duplicate - eek!! I guess there's no way to check for this w/ my (sbaxter's code, that I revised) Code:
Private Sub orgAdd_Click()
Dim DAOdb As Database
Dim DAOrs As Recordset
Dim sSQL As String
Set DAOdb = CurrentDb()
s = "tblOrg"
Set DAOrs = DAOdb.OpenRecordset(s)
With DAOrs
.AddNew
.Fields("Org") = Me.Organization
.Fields("Address1") = Me.Address
'.Fields("Address2") = Me hmmm.... ***
.Fields("City") = Me.CITY
.Fields("State") = Me.STATE
.Fields("Zip") = Me.ZIP
.Update
End With
MsgBox ("Organization: """ & Me.Organization & """ Added")
DAOrs.Close
DAOdb.Close
End Sub
*** Long story short.., because the other app I need to copy and paste this field to is just an MEMO field (multi-line textbox) I haven't yet found the proper solution to this. Either I have two fields (add1 and add2) (see above) or keep addr1 and addr2 and include a MEMO in my tblOrg field, and in code, just concatenate these fields, or not. I don't know yet. I have to see how my db, and tables work or relate to the other (outside app) that I'm actually posting to. Like I said, it's a long story ![]() So, just ignore this "***" field for now ![]() >> Reminder: Add the Reference to the DAO Library If you'll forgive me, I don't have the faintest idea what you mean by this ![]() Many thanks, -myaccess |
![]() |
| Viewing: ASP Free Forums > Database > Microsoft Access Help > How do I ADD to a table from main form? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|