Data entry for a table from a form

H

haas.chaudhry

Hi all!

I'm a newbie when it comes to programming VBA and I need some help here. For the sake of simplicity, I am giving an example for just two fields so I can learn the programming technique to capture data entered into a form to be added to a table:

I have a table called tblContacts
There are two fields in this table: CompanyName and PhoneNumber

I created a form where the user can see if a company name exists through a Combo Box with the source being the list of entries in the tblContacts field - if it doesn't, he enters a new company into the a txtCompanyName box and a phone number into the txtPhoneNumber box on the form. Next, user presses a button on the form which would call a VBA procedure which runs and takes the values from txtCompanyName and txtPhoneNumber and adds to the tblContacts table

I know that you can do this easily through Form Wizard, but I wanted to know how to program this into a VBA procedure. This is a simple example to learn the technique so I cna apply it to one with multiple fields, etc.

Thank you for your help in advance!
 
A

Access Developer

You don't need any VBA code to "move the data from the form to the table".
Use the table as the RecordSource of the Form, and the data will
automatically be saved to the table when you move to the next record, close
the form, move from the main form into a subform control, or explicitly
save. Saving to the table without explicit code is hard for some developers
to accept, but it is one of the primary strengths of Access.

--
Larry Linson
Microsoft Office Access MVP
Co-Author, Microsoft Access Small Business Solutions, Wiley 2010

Hi all!

I'm a newbie when it comes to programming VBA and I need some help here. For
the sake of simplicity, I am giving an example for just two fields so I can
learn the programming technique to capture data entered into a form to be
added to a table:

I have a table called tblContacts
There are two fields in this table: CompanyName and PhoneNumber

I created a form where the user can see if a company name exists through a
Combo Box with the source being the list of entries in the tblContacts
field - if it doesn't, he enters a new company into the a txtCompanyName box
and a phone number into the txtPhoneNumber box on the form. Next, user
presses a button on the form which would call a VBA procedure which runs and
takes the values from txtCompanyName and txtPhoneNumber and adds to the
tblContacts table

I know that you can do this easily through Form Wizard, but I wanted to know
how to program this into a VBA procedure. This is a simple example to learn
the technique so I cna apply it to one with multiple fields, etc.

Thank you for your help in advance!
 
H

haas.chaudhry

You don't need any VBA code to "move the data from the form to the table".

Use the table as the RecordSource of the Form, and the data will

automatically be saved to the table when you move to the next record, close

the form, move from the main form into a subform control, or explicitly

save. Saving to the table without explicit code is hard for some developers

to accept, but it is one of the primary strengths of Access.



--

Larry Linson

Microsoft Office Access MVP

Co-Author, Microsoft Access Small Business Solutions, Wiley 2010





Hi all!



I'm a newbie when it comes to programming VBA and I need some help here. For

the sake of simplicity, I am giving an example for just two fields so I can

learn the programming technique to capture data entered into a form to be

added to a table:



I have a table called tblContacts

There are two fields in this table: CompanyName and PhoneNumber



I created a form where the user can see if a company name exists through a

Combo Box with the source being the list of entries in the tblContacts

field - if it doesn't, he enters a new company into the a txtCompanyName box

and a phone number into the txtPhoneNumber box on the form. Next, user

presses a button on the form which would call a VBA procedure which runs and

takes the values from txtCompanyName and txtPhoneNumber and adds to the

tblContacts table



I know that you can do this easily through Form Wizard, but I wanted to know

how to program this into a VBA procedure. This is a simple example to learn

the technique so I cna apply it to one with multiple fields, etc.



Thank you for your help in advance!

Larry,

I specifically said that I know this can be done through Form Wizard in terms of recordSource or whatever, but was specifically looking for code. Can anyone please help with this? Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top