PDA

View Full Version : Solved: Updating one Table Changes Another



Imdabaum
07-26-2006, 03:02 PM
I have two tables that are being affected. One purposefully, and the second one is a bug. tblDisplayImage stores a Master Image to be displayed in a Profile. It is selected from tblPhotos.

I have a main form that holds information from users. There is a photos subform, that allows users to add photos to their page. The form has a listbox that allows you to display the photo selected Where ID= UserID. This listbox is populated from tblPhotos with same criteria.

Then I have a form that sets the value of imageLocation in tblDisplayImage. The selection is made by selecting a photo from a combo box that is populated from tblPhotos Where ID= userID. I have a button that performs the following operation when I have selected the desired photo from the Combo box.


Private Sub cmdsetImage_Click()
Dim imgAddress As String
Dim imgCaption As String
Dim strCriteria As String
Dim db As Database
Dim rst As Recordset

Set db = CurrentDb
strCriteria = "ID = " & Me.UserID
Set rst = db.OpenRecordset("tblDisplayImages", dbOpenDynaset)
If Not IsNull(Me.cboImages.Column(2)) Then
imgAddress = Me.cboImages.Column(2)
Else
imgAddress = vbNullChar
End If
rst.FindFirst strCriteria

If rst.NoMatch Then
With rst
.AddNew
!PropertyID = Me.PropertyID
!location = imgAddress
.Update
rst.Close
End With
Else
With rst
.Edit
!PropertyID = Me.PropertyID
!location = imgAddress
.Update
rst.Close
End With
End If
DoCmd.Close acForm, "frmTitleImageSelect"
End Sub

For some reason when we click the accept button it changes the caption value for the first item in the subForm's listbox.

Imdabaum
08-02-2006, 12:40 PM
Well I changed the structure of the tblPhotos to hold a displayFlag field. It is a yes/No data type. Then when I call the set display image function I cycle through all photos that are associated with the user and set them to false. Then I find the one that was selected in the list box and set that displayFlag =True. OnCurrent Event finds the photo with the displayFlag and sets it's image location to the picture on the title bar. Don't know why I didn't think of doing that before.