Opening another form from a list box

RyanB

Registered User.
Local time
Today, 12:20
Joined
Jul 13, 2004
Messages
53
Hi All,

Trying to open another form from a list box and have it carry the value over to select the correct record.

But i keep getting 'The operform action was cancelled' error.

My Code:
Option Compare Database

Private Sub lstAR_DblClick(Cancel As Integer)
DoCmd.OpenForm "frmMaint", acNormal, , "[AR Number] = " & Me![lstAR], acFormEdit, acDialog

End Sub

This is annoying the hell outta me and i bet its something small and stupid aswell.

Ryan
 
RyanB said:
DoCmd.OpenForm "frmMaint", acNormal, , "[AR Number] = " & Me![lstAR], acFormEdit, acDialog

It may not be this line of code that is causing the error, but elsewhere. Try:

DoCmd.OpenForm "frmMaint"

then

DoCmd.OpenForm "frmMaint", , , "[AR Number] = " & Me![lstAR],

the acNormal is the default so is not required. The acFormEdit and acDialog can be set from the form you are trying to open.

Edit...

On reviewing your code, try

DoCmd.OpenForm "frmMaint", acNormal, , "[AR Number] = " & Me.lstAR

( A . rather than a !)

Dave
 
Last edited:
Hi,

Thanks for your help. I tried that code but got the same error.

There isn't really any other code on the form as of yet, so i'm not sure what other code could be causing a problem.

Cheers
 
Are Form1s Modal & PopUp properties set to true? Is Form2s PopUp property set to true?

Try setting them all to false.
 
I have code in my system in my house. I will post this tonight...pls. wait..
 
Here is my code for the main form, including how the listbox gets its data:

Option Compare Database
Option Explicit

Private Sub Form_Load()
Dim strSQL As String

If Me![lstAR].ListCount > 0 Then
strSQL = "SELECT tblAR.* " _
& "FROM tblAR " _
& "WHERE (((tblAR.completed) Is Null))" _
& "AND ((tblAR.[AR Number]) =" & Me![lstAR].ItemData(1) & ");"
Else
strSQL = "SELECT tblAR.* " _
& "FROM tblAR " _
& "WHERE (((tblAR.completed) Is null)) " _

End If
Debug.Print strSQL
Me.RecordSource = strSQL
Me.Requery

End Sub

Private Sub lstRequests_Click()
Dim strSQL

If IsNull(Me![lstRequests]) Then
Exit Sub
Else
strSQL = "SELECT tblAR.* " _
& "FROM tblAR " _
& "WHERE (((tblAR.Completed)Is Null)) " _
& "AND ((tblAR.[AR Number]) =" & Me![lstAR] & ");"
Debug.Print strSQL
Me.RecordSource = strSQL
Me.Requery
End If
End Sub

Private Sub lstAR_DblClick(Cancel As Integer)
DoCmd.OpenForm "frmMaint", acNormal, , "[AR Number] = " & Me![lstAR], acFormEdit, acDialog

End Sub
 
As promised before sending the code :

It is useful , when you double click on a row in a list box, to open a form related to that record.

Private Sub List11_DblClick(Cancel As Integer)
On Error GoTo Err_SearchList_DblClick
Dim db As DAO.Database
Dim rst As DAO.Recordset
DoCmd.OpenForm "Consultant_Form"

Set rst = Forms![Consultant_Form].Recordset.Clone

rst.FindFirst "[Consultant_ID] = " & Me.List11
Forms![Consultant_Form].Bookmark = rst.Bookmark


Exit_SearchList_DblClick:
Exit Sub

Err_SearchList_DblClick:
MsgBox Err.Description
Resume Exit_SearchList_DblClick

End Sub

Thanks.

HTH

DavidCdp1
 
Thanks for the code, I gave it a shot and got the error 'Data Type Mismatch in criteria expression'.

It gets futher than it did before the second form acctually opens but after the error only bring up the first record.
 
Yay!!!!

All fixed, the 'AR_Number' field was set as 'TEXT' in the table when it should of been a 'NUMBER'

Thanks all!!
 

Users who are viewing this thread

Back
Top Bottom