XLEAccessGuru
XLEGuru
- Local time
- Today, 06:09
- Joined
- Nov 17, 2006
- Messages
- 65
This is probably simple, but I'm stuck.
I have a Form1.ListBox 1 on Form1 that contains several rows of data from TableA. On the OnClick event of a button on Form1, I need to refresh Form2.Recordsource (a different form) to contain only the items in Form1.ListBox1, but from a different table - TableB - based on related field [ProfileID]. I need to extract the [ProfileID] numbers from Form1.ListBox1 and create a new recordsource to pull records that match those [ProfileID] numbers.
So far I've got the code below but I need to modify 'stSQL' to be the new recordsource for Form2 based on the data in Form1.ListBox1.
If you look where it says:
...this is where the recordsource gets refreshed, but stSQL isn't quite right.
Any help is hugely appreciated as always!!! Here's the code.
I have a Form1.ListBox 1 on Form1 that contains several rows of data from TableA. On the OnClick event of a button on Form1, I need to refresh Form2.Recordsource (a different form) to contain only the items in Form1.ListBox1, but from a different table - TableB - based on related field [ProfileID]. I need to extract the [ProfileID] numbers from Form1.ListBox1 and create a new recordsource to pull records that match those [ProfileID] numbers.
So far I've got the code below but I need to modify 'stSQL' to be the new recordsource for Form2 based on the data in Form1.ListBox1.
If you look where it says:
Code:
With Forms!frmIUPSetupModify
.RecordSource = stSQL
.Requery
End With
...this is where the recordsource gets refreshed, but stSQL isn't quite right.
Any help is hugely appreciated as always!!! Here's the code.
Code:
Private Sub cmdOK_Click()
On Error GoTo ErrHandle
Dim stSQL As String
Dim stWhere As String
stSQL = "SELECT tblProjectsImport.* FROM tblValidation INNER JOIN tblProjectsImport " _
& "ON tblValidation.ProfileRecordID = tblProjectsImport.ProfileID WHERE (((tblValidation.TID)=" & iTID & ") "
Select Case stCurProfType
Case "IUP - Setup or Modify Content"
stWhere = "AND ((tblProjectsImport.Type)='IUP - Setup or Modify Content'));"
stSQL = stSQL & stWhere
With Forms!frmIUPSetupModify
.RecordSource = stSQL
.Requery
End With
Case "Create New"
stWhere = "AND ((tblProjectsImport.Type)='Create New'));"
stSQL = stSQL & stWhere
With Forms!frmBuildNewDefaultAssign
.RecordSource = stSQL
.Requery
End With
Case "Default-Existing: Assign"
stWhere = "AND ((tblProjectsImport.Type)='Default-Existing: Assign'));"
stSQL = stSQL & stWhere
With Forms!frmDefaultExistingAssign
.RecordSource = stSQL
.Requery
End With
End Select
DoCmd.Close acForm, "frmValidationReport"
Exit_ErrHandle:
Exit Sub
ErrHandle:
MsgBox Err.Description, vbCritical, "Error: " & Err.Number
Resume Exit_ErrHandle
End Sub