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

DoCmd.OpenForm problems

P: 20
Hi,

I am using Access 2003. I have a list box on a form which has 6 columns in it, with data taken from a table. I have an unbound text box which holds the ID number for the selected item in the list box. I have a command button which I want to use to open another form on that record. At the moment it opens the other form but only to the first record. The other form has its recordset set to the same table as what the list box displays certain data for. Basically, the list box displays certain more important data, and the user clicks on the item to be viewed and then the next form displays all the data.

I have used this code to try and open the form to the correct record with no luck:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmbSelected_Click()
  2.  
  3. Dim stLinkCriteria As String
  4.  
  5.     stLinkCriteria = "[RiskEstimateID] = '" & Me.txtLstRPET & "'"
  6.  
  7.     DoCmd.OpenForm "RiskEstimating", acNormal, , stLinkCriteria, , acNormal
  8.  
  9. End Sub
  10.  
I have also tried to open the form with OpenArgs with no luck, like this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmbSelected_Click()
  2.  
  3.     DoCmd.OpenForm "RiskEstimating", acNormal, , , , acNormal, Me.txtLstRPET
  4.  
  5. End Sub
  6.  
  7.  
  8. Private Sub Form_Open(Cancel As Integer)
  9.  
  10.     Me.RiskEstimateID = Me.OpenArgs
  11.  
  12. End Sub
  13.  
I have tried debugging and going through the code and in theory it should work, but it just doesn't. If say the ID number is 4 for the selected item in the list box, then the value in txtLstRPET goes to 4. For the stLinkCriteria it says "[RiskEstimateID] = '4', but the 4th record doesn't display in the form when opened.

Many thanks in advance,

Andrew
Mar 10 '08 #1
Share this Question
Share on Google+
1 Reply


P: 20
I sorted this out now. I removed the record source completely from the 2nd form being opened (which was the table for the form), ran the program, then put the record source back in, closed and reopened the database and ran the program again and it worked. I think Access got lost on what variables it had when I had errors trying to solve it.
Mar 12 '08 #2

Post your reply

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