By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,903 Members | 2,042 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,903 IT Pros & Developers. It's quick & easy.

open new form to specific record with multiple constraints

P: 5
Hi,

I am a very new user to access databases, i'm trying to create a command button that opens a new form to a spefic record with multiple matching keys, if there is no match then start a new record. Is there a way can modify this code to add it?

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command285_Click()
  2. On Error GoTo Err_Command285_Click
  3.  
  4.     Dim stDocName As String
  5.     Dim stLinkCriteria As String
  6.  
  7.     stDocName = "MyPopupForm"
  8.  
  9.     stLinkCriteria = "[matchingValue]=" & "'" & Me![matchingValueHere] & "'"
  10.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  11.  
  12. Exit_Command285_Click:
  13.     Exit Sub
  14.  
  15. Err_Command285_Click:
  16.     MsgBox Err.Description
  17.     Resume Exit_Command285_Click
  18.  
  19. End Sub
I have also tried an And statement in the stLinkCriteria string but it doesnt work

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command285_Click()
  2. On Error GoTo Err_Command285_Click
  3.  
  4.     Dim stDocName As String
  5.     Dim stLinkCriteria As String
  6.  
  7.     stDocName = "MyPopupForm"
  8.  
  9.     stLinkCriteria = "[matchingValue]=" & "'" & Me![matchingValueHere] & "'" And "[matchingValue2]=" & "'" & Me![matchingValueHere2] & "'"
  10.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  11.  
  12. Exit_Command285_Click:
  13.     Exit Sub
  14.  
  15. Err_Command285_Click:
  16.     MsgBox Err.Description
  17.     Resume Exit_Command285_Click
  18.  
  19. End Sub
Jun 4 '07 #1
Share this Question
Share on Google+
1 Reply


MMcCarthy
Expert Mod 10K+
P: 14,534
The And needs to be inside the string as follows:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command285_Click()
  2. On Error GoTo Err_Command285_Click
  3.  
  4. Dim stDocName As String
  5. Dim stLinkCriteria As String
  6.  
  7.     stDocName = "MyPopupForm"
  8.  
  9.     stLinkCriteria = "[matchingValue]=" & "'" & Me![matchingValueHere] & "' And [matchingValue2]=" & "'" & Me![matchingValueHere2] & "'"
  10.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  11.  
  12. Exit_Command285_Click:
  13.     Exit Sub
  14.  
  15. Err_Command285_Click:
  16.     MsgBox Err.Description
  17.     Resume Exit_Command285_Click
  18.  
  19. End Sub
Jun 6 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.