Microsoft Access Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft Access Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 28th, 2007, 01:59 PM
bajones bajones is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Posts: 3 bajones User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 m 11 sec
Reputation Power: 0
Combo box storing values into table

Hi all

I've been given the task of improving and adding a few features to an access db, and I've run into some potential problems...

One of the forms has combobox that stores a foreign key and a text value in the main data table. There is an associated numerical value, that I also want inserted into the main table from the combo box, but it only seems to allow the one value. Using Access 2003.

any help much appreiciated.

Reply With Quote
  #2  
Old July 29th, 2007, 06:12 AM
zintrac zintrac is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Posts: 50 zintrac User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 50 m 50 sec
Reputation Power: 2
You need to do it in code First make sure the combo box rowsource contains all 3 values and is set to have 3 columns. These are referred to as YourComboName.Column(0) as the first (usually index) column and .column(1) as the second etc. In the afterUpdate event Open a recordset on your table with the index as WHERE clause and Update your field with the column values. If you need a code example let me know.

Reply With Quote
  #3  
Old July 29th, 2007, 06:57 AM
bajones bajones is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Posts: 3 bajones User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 m 11 sec
Reputation Power: 0
Thanks! I'll give it a go

/edit: Actually, if you had some example code to hand, that'd be really great.

Reply With Quote
  #4  
Old July 30th, 2007, 09:22 AM
zintrac zintrac is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Posts: 50 zintrac User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 50 m 50 sec
Reputation Power: 2
sadly I don't seem to be able to attach a sample but here's some code for the after update event that works

Combo 10 is bound to the Main Table . It (the Combo) has 3 columns. The rowsource is a query on the 3 fields in the Lookup Table (LUTable)

SELECT LUTable.LUTableKey, LUTable.LUTableText, LUTable.LUTableNum FROM LUTable;

'In my case column width fot the key field is set to 0cm and is bound to the foreign key [LUTableKey] in the Main Table

Private Sub Combo10_AfterUpdate()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim prm As DAO.Parameter
'Dim strSQL As String
Dim rs As Recordset
Set db = CurrentDb

If Me.Dirty Then
Me.Dirty = False
End If

' these two textboxes are unbound and invisible

Me!txtLUTableText = ""
Me!txtLUTableNum = Null
Me!txtLUTableText = Me!Combo10.Column(1)
Me!txtLUTableNum = Me!Combo10.Column(2)

Set qdf = db.QueryDefs("Query1")

' Query1 is a stored query on the main table with criteria that
' references the main table index in a bound text box on the form
' The main table has the similar fields as the lookup table and 'whatever others. Mine includes "Description"

' Important housekeeping

For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rs = qdf.OpenRecordset

'this just makes sure a record exists

If rs.EOF And rs.BOF Then
MsgBox "Enter a Description"
Me!Description.SetFocus
Exit Sub
Else
rs.Edit

'pass the values from the unbound controls to the Main Table

rs!LUTableText = Me!txtLUTableText
rs!LUTableNum = Me!txtLUTableNum
rs.Update
End If

End Sub

hope you can follow this and it helps - cheers

Reply With Quote
  #5  
Old July 30th, 2007, 01:06 PM
bajones bajones is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Posts: 3 bajones User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 m 11 sec
Reputation Power: 0
Thanks! that looks great. I'll give it whirl

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft Access Development > Combo box storing values into table


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 3 hosted by Hostway
Stay green...Green IT