PC Review


Reply
Thread Tools Rate Thread

Add records to table from Datsheet

 
 
=?Utf-8?B?QWxsYW4gU2t5bmVy?=
Guest
Posts: n/a
 
      30th Aug 2006
Using Access 2000.
I have 3 tables;
Suppliers (listing all supplier details with unique SupplierID).
Products (2 columns listing ProductID and ProductName)
Contract (3 columns listing unique ContractID, SupplierID and ProductID)

On my main form showing all details per supplier from suppliers table and
listing products supplied by supplier in a list box.

Currently there is a command button on my form1 that opens another form2 to
add a product to a supplier using a text box to enter the 8 digit ProductID
(if known). If not known, on form2 there is a command button that opens
another form3 which enables users to free text search the
products.productname field and the results are displayed in form4 in
datasheet view. This allows the user to find and read the correct ProductID
and then close form4 & form3 and then enter the right ProductID using form2.

This is a lot of command buttons and forms which I am trying to reduce,
merge or simplify. My plan is to merge the functionalities from form2 & 3
into one, which I can safely manage.

What I would like assistance with, if possible, is that when a user does a
search which opens the resultsform in datasheet view (2 columns ProductID,
ProductName) I want them to have the ability to double-click the right
ProductID and this adds that code to that supplier (i.e. the SupplierID and
ProductID are added to the Contract table).

It is more likely that there will be several products added from a single
search, this is why I would like to simplify operations so users can simply
scroll down the list double-clicking the ProductID's that each supplier
supplies.

I'm sure this can be done using the double-click event procedure, I'm
getting a bit lost with the code to complete the task.

Sorry this is a bit long-winded and I thank anyone in advance of some
assistance with the code or some pointers in the right direction.

Best regards

Allan
 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWljaGFlbCBI?=
Guest
Posts: n/a
 
      30th Aug 2006
Hi.

I can't say this is necessarily the best way to do it, but one solution is
to put code similar to the below into the ListBox's DoubleClick event:

Private Sub ListBoxName_DblClick(Cancel As Integer)
Dim strSQL As String

strSQL = "INSERT INTO Contract([SupplierID], [ProductID]) VALUES (" _
& Me.ListBoxName.Column(0) & ", " _
& Me.ListBoxName.Column(1) & ")"

CurrentDb.Execute strSQL, dbFailOnError
End Sub


A few points of interest:
- The code assumes the ContractID field in the Contract table is an
AutoNumber field
- The code assumes the SupplierID and ProductID fields are numeric
- The code assumes the values you want to insert into these fields are
contained in columns 0 and 1 of the ListBox
- There is currently no error checking
- You will probably want to add some sort of a confirmation (a MessageBox
after the CurrentDb.Execute line, perhaps), otherwise the user may be unaware
that anything has happened after double-clicking on the ListBox.
- If your forms display any controls bound to the Contract table, you will
probably want to add code after the CurrentDb.Execute line that requeries
those controls.

Please be aware that the above is untested, and there may be other important
info I am omitting, but this will hopefully get you started. Feel free to
post back with any problems or questions.

-Michael

"Allan Skyner" wrote:

> Using Access 2000.
> I have 3 tables;
> Suppliers (listing all supplier details with unique SupplierID).
> Products (2 columns listing ProductID and ProductName)
> Contract (3 columns listing unique ContractID, SupplierID and ProductID)
>
> On my main form showing all details per supplier from suppliers table and
> listing products supplied by supplier in a list box.
>
> Currently there is a command button on my form1 that opens another form2 to
> add a product to a supplier using a text box to enter the 8 digit ProductID
> (if known). If not known, on form2 there is a command button that opens
> another form3 which enables users to free text search the
> products.productname field and the results are displayed in form4 in
> datasheet view. This allows the user to find and read the correct ProductID
> and then close form4 & form3 and then enter the right ProductID using form2.
>
> This is a lot of command buttons and forms which I am trying to reduce,
> merge or simplify. My plan is to merge the functionalities from form2 & 3
> into one, which I can safely manage.
>
> What I would like assistance with, if possible, is that when a user does a
> search which opens the resultsform in datasheet view (2 columns ProductID,
> ProductName) I want them to have the ability to double-click the right
> ProductID and this adds that code to that supplier (i.e. the SupplierID and
> ProductID are added to the Contract table).
>
> It is more likely that there will be several products added from a single
> search, this is why I would like to simplify operations so users can simply
> scroll down the list double-clicking the ProductID's that each supplier
> supplies.
>
> I'm sure this can be done using the double-click event procedure, I'm
> getting a bit lost with the code to complete the task.
>
> Sorry this is a bit long-winded and I thank anyone in advance of some
> assistance with the code or some pointers in the right direction.
>
> Best regards
>
> Allan

 
Reply With Quote
 
=?Utf-8?B?QWxsYW4gU2t5bmVy?=
Guest
Posts: n/a
 
      31st Aug 2006
Hi Michael

Thanks for your reply, which has given me good food for thought.

Further to your assumptions the values which I'm inserting into the
Contracts table are ContractID [autonumber for this table]; SupplierID
[autonumber from Suppliers table]; ProductID [8 digit standard number]. The
ContractID will self generate when new record added, the SupplierID will come
from the form displaying the supplier record (form1) and the ProductID comes
from a form that displays search results in datasheet view (2 textbox
controls showing ProductID and ProductName).

I am trying to adapt your suggestion but any further help you can give will
be greatly appreciated.

Allan

"Michael H" wrote:

> Hi.
>
> I can't say this is necessarily the best way to do it, but one solution is
> to put code similar to the below into the ListBox's DoubleClick event:
>
> Private Sub ListBoxName_DblClick(Cancel As Integer)
> Dim strSQL As String
>
> strSQL = "INSERT INTO Contract([SupplierID], [ProductID]) VALUES (" _
> & Me.ListBoxName.Column(0) & ", " _
> & Me.ListBoxName.Column(1) & ")"
>
> CurrentDb.Execute strSQL, dbFailOnError
> End Sub
>
>
> A few points of interest:
> - The code assumes the ContractID field in the Contract table is an
> AutoNumber field
> - The code assumes the SupplierID and ProductID fields are numeric
> - The code assumes the values you want to insert into these fields are
> contained in columns 0 and 1 of the ListBox
> - There is currently no error checking
> - You will probably want to add some sort of a confirmation (a MessageBox
> after the CurrentDb.Execute line, perhaps), otherwise the user may be unaware
> that anything has happened after double-clicking on the ListBox.
> - If your forms display any controls bound to the Contract table, you will
> probably want to add code after the CurrentDb.Execute line that requeries
> those controls.
>
> Please be aware that the above is untested, and there may be other important
> info I am omitting, but this will hopefully get you started. Feel free to
> post back with any problems or questions.
>
> -Michael
>
> "Allan Skyner" wrote:
>
> > Using Access 2000.
> > I have 3 tables;
> > Suppliers (listing all supplier details with unique SupplierID).
> > Products (2 columns listing ProductID and ProductName)
> > Contract (3 columns listing unique ContractID, SupplierID and ProductID)
> >
> > On my main form showing all details per supplier from suppliers table and
> > listing products supplied by supplier in a list box.
> >
> > Currently there is a command button on my form1 that opens another form2 to
> > add a product to a supplier using a text box to enter the 8 digit ProductID
> > (if known). If not known, on form2 there is a command button that opens
> > another form3 which enables users to free text search the
> > products.productname field and the results are displayed in form4 in
> > datasheet view. This allows the user to find and read the correct ProductID
> > and then close form4 & form3 and then enter the right ProductID using form2.
> >
> > This is a lot of command buttons and forms which I am trying to reduce,
> > merge or simplify. My plan is to merge the functionalities from form2 & 3
> > into one, which I can safely manage.
> >
> > What I would like assistance with, if possible, is that when a user does a
> > search which opens the resultsform in datasheet view (2 columns ProductID,
> > ProductName) I want them to have the ability to double-click the right
> > ProductID and this adds that code to that supplier (i.e. the SupplierID and
> > ProductID are added to the Contract table).
> >
> > It is more likely that there will be several products added from a single
> > search, this is why I would like to simplify operations so users can simply
> > scroll down the list double-clicking the ProductID's that each supplier
> > supplies.
> >
> > I'm sure this can be done using the double-click event procedure, I'm
> > getting a bit lost with the code to complete the task.
> >
> > Sorry this is a bit long-winded and I thank anyone in advance of some
> > assistance with the code or some pointers in the right direction.
> >
> > Best regards
> >
> > Allan

 
Reply With Quote
 
 
 
Reply

Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hide record selector when displaying Access form in datsheet view Luis in IT Microsoft Access Database Table Design 1 13th Aug 2008 05:15 PM
Datsheet view Knew2 Microsoft Access 2 25th Jun 2008 09:38 PM
Copy Records from Access Database table(more than 5 lakh records in this table) to Excel Sheet divya Microsoft Excel Programming 1 26th Oct 2006 12:12 PM
Continous subform acting like datsheet view =?Utf-8?B?Sm9lIE1pbGxlcg==?= Microsoft Access Forms 2 11th Jul 2006 06:46 PM
select all records on one table but limit records from 2nd table =?Utf-8?B?am9hbg==?= Microsoft Access Queries 8 3rd Nov 2004 01:38 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:20 PM.