Connecting Tech Pros Worldwide Forums | Help | Site Map

DoCmd.OpenForm problems

Newbie
 
Join Date: Oct 2007
Posts: 20
#1: Mar 10 '08
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
Newbie
 
Join Date: Oct 2007
Posts: 20
#2: Mar 12 '08

re: DoCmd.OpenForm problems


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.
Reply


Similar Microsoft Access / VBA bytes