Making use of a list box

Kryst51

Singin' in the Hou. Rain
Local time
Yesterday, 23:41
Joined
Jun 29, 2009
Messages
1,896
OK, I am new to this forum. First off I want to say, that Ihave spent two days researching this issue, both through the internet and two books I own on Access databases and do not understand the answers that I have found.

I have a form that I want to add records from a linked table to. The way I want to accomplish this is to click a button on the form, and open another form. This second form has a list box that is set to multiple extended option. I want to be able to select the records from the list box, and update the foreign key that is in the table the list box is being populated by to the primary key that is being displayed in the first form. I want it to update the field when I click a button.

I have taken certain steps that I thought might make this easier.

1. The forms and list box have been created.
2. I have added a text box to the second form that pulls in the value of the primary key of the first form, hoping that this would be eaier to refer to.

I am doing all this in hopes of automating a task, where I copy info from a database to a spreadsheet, wher I modify the data how I want it to appear, and maintain the spreadsheet throughout the month. As it is workk related, I don't know that I can share my database, but I could make a dummy one, although i am not sure I am allowed to do attachments yet.

Any help would be greatly appreciated. I have checked out other forums, and know that This probably involves some looping statements in VBA, but when I apply the codes that I have found and inserted my custom fields I cannot get it to work. The books I have do not explain it very well.

Again Thank you:)

Kryst
 
Thank you so much for your response. I looked at your sample database, and it is almost exactly what I Want except reversed. In my database, the "other" table is populating the list box, and I want to select the records, click the button and have it put in the employee ID so that the two records are linke. I will try to play around with your database and the code you gave to see if I can figure it out. I have taught myself, mostly, about access, and am starting to learn some about vba, but obviously still have a long way to go.

Thanks again,

Kryst
 
I'm obviously confused, and might still be. If you're trying to update the existing records from the listbox, rather than a recordset I'd execute SQL within that loop. This type of thing:

CurrentDb.Execute "UPDATE TableName SET FieldName = " & TextboxName & " WHERE KeyField = " & ctl.ItemData(varItem)
 
I don't have time right now, but later this evening I will create a dummy database, and show you my best attempt at achieving the outcome I want. The truth is that I have not been dealing with code for very long, and am teaching myself. This is probably over my head as far as understanding is concerned. I have only done pretty simple things...

At any rate, I hope to alleviate your confusion (and mine) about what I am asking later tonight after I get home from work.

Thanks again,

Kryst
 
Ok..... I finally had the opportunity to make the dummy database. And as I said before, I really don't know what to do..... I tried to include notes about what I want it to do. I really hope It can help. Oh... In my actual database the "DebitAmounts table" is populated by a bunch of different queries. And gets appended to more than daily.
 

Attachments

Like so?

Code:
  Dim db            As DAO.Database
  Dim ctl           As Control
  Dim varItem       As Variant
  
  On Error GoTo Err_Command3_Click
  
  Set db = CurrentDb()
  Set ctl = Me.List0
  
  For Each varItem In ctl.ItemsSelected
    CurrentDb.Execute "UPDATE DebitAmounts SET DebitMemoID = " _
                    & Forms!debitmemoentry.DebitMemoID _
                    & " WHERE DebitAmountID = " & ctl.ItemData(varItem)
  Next varItem

Exit_Command3_Click:
  Set ctl = Nothing
  Set db = Nothing
  Exit Sub

Err_Command3_Click:
  MsgBox Err.Description
  Resume Exit_Command3_Click
 
You are awesome! That works perfectly! Thank you SOOOO much!!!! I am about to analyze it, so I can understand it, now that I can see it with terms I can understand.....
 
No problem Kryst. Here's the other one:

Code:
Private Sub Check6_AfterUpdate()
  If Me.Check6 = True Then
    Me.List0.RowSource = "SELECT DebitAmountID, AmountDescription, Value, Unit, " _
                       & "Identifier, DebitMemoID FROM DebitAmounts WHERE DebitMemoID = 0"
  Else
    Me.List0.RowSource = "SELECT DebitAmountID, AmountDescription, Value, Unit, " _
                       & "Identifier, DebitMemoID FROM DebitAmounts"
  End If
End Sub
 
Thank you!!! Being able to learn this stuff makes me so happy.
 

Users who are viewing this thread

Back
Top Bottom