Microsoft Access Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft Access Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old December 6th, 2003, 01:00 PM
myaccess myaccess is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: usa
Posts: 6 myaccess User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old December 7th, 2003, 03:41 PM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 12
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-

Reply With Quote
  #3  
Old December 7th, 2003, 03:52 PM
myaccess myaccess is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: usa
Posts: 6 myaccess User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #4  
Old December 7th, 2003, 04:42 PM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 12
"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-

Reply With Quote
  #5  
Old December 7th, 2003, 05:01 PM
myaccess myaccess is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: usa
Posts: 6 myaccess User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
@ 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

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft Access Help > How do I ADD to a table from main form?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway