Help me modify this code so it links TWO fields instead of just one

t3nchi

Registered User.
Local time
Yesterday, 22:29
Joined
Sep 28, 2005
Messages
79
According to this code, I assume it's opening a form and linking the 'dateIncidents'. I want it to link another field as well. How do I modify it correctly?

What I basically want to do is:

1) Click Add Record
2) It opens a new form that displays a bunch of new info to enter...which is related to the SAME record. To relate it, I need to link two fields. 'dateIncident' and 'companyName'.


Code:
Private Sub Add_Click()

Dim stDocName As String
Dim stLinkCriteria1 As String

Select Case Me.incidentResolvedYN
    
    Case False
        '--DoCmd.OpenForm "frm_addIncidentReport_page1"
        
        stDocName = "frm_addIncidentReport_page1"
    
        stLinkCriteria = "[dateIncident]=" & Me![dateIncident]

        DoCmd.OpenForm stDocName, , , stLinkCriteria1
    
    
    Case Else
        '--Do nothing
        
    End Select
    
On Error GoTo Err_Add_Click


    DoCmd.GoToRecord , , acNewRec

Exit_Add_Click:
    Exit Sub

Err_Add_Click:
    MsgBox Err.Description
    Resume Exit_Add_Click
    
End Sub
 
stLinkCriteria = "[dateIncident]=" & Me![dateIncident] & " AND [companyName] = '" & Me![companyName] &"'"

HTH

Peter
 
Hmm,thanks but that didn't seem to do the trick...Here's what I have in my code for the "add" button.

Code:
Private Sub Add_Click()

Dim stDocName As String
Dim stLinkCriteria As String


Select Case Me.incidentResolvedYN
    
    Case False
        '--DoCmd.OpenForm "frm_addIncidentReport_page1"
        
        stDocName = "frm_addIncidentReport_page1"
    
        stLinkCriteria = "[dateIncident]=" & Me![dateIncident] & "AND [nameQSEorTO]= ' " & Me![nameQSEorTO] & " ' "
        DoCmd.OpenForm stDocName, , , stLinkCriteria
    
    
    Case Else
        '--Do nothing
        
    End Select
    
On Error GoTo Err_Add_Click


    DoCmd.GoToRecord , , acNewRec

Exit_Add_Click:
    Exit Sub

Err_Add_Click:
    MsgBox Err.Description
    Resume Exit_Add_Click
    
End Sub
 
thats bcoz you have entered a space in the begining and at the end of the field me![nameQSEorTO] -

try this line hopefully this should resolve the issue with date as well .....

stLinkCriteria = "[dateIncident] = #" & Me![dateIncident] & "# AND [nameQSEorTO] = '" & Me![nameQSEorTO] & "'"
 

Users who are viewing this thread

Back
Top Bottom