Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Run-time error '2448': you cant assign a value to this object

Posted on 2005-03-10
4
Medium Priority
?
344 Views
Last Modified: 2008-02-26
Hi, I have a list box where the user selects a record to be opened by double clicking the record, or selecting said record and clicking the open record button. However if the user clicks open record button before a record is selected then I get...

Run-time error '2448':
you cant assign a value to this object.

the code highlighted is:

Private Sub Form_Open(Cancel As Integer)
   
    If Len(Nz(Me.OpenArgs)) > 0 Then
          Me.Filter = Me.OpenArgs        'this line is highlighted in debug
          Me.FilterOn = True
End If

End Sub

this code is in the main form where the selected record would be displayed.

I want to be able to catch this error and output my own msg ie. "you must select a record before opening"

B

0
Comment
Question by:BobNZ2
  • 2
  • 2
4 Comments
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 13510219
Try this:

Private Sub Form_Open(Cancel As Integer)
On Error Goto OpenError:
    If Len(Nz(Me.OpenArgs)) > 0 Then
          Me.Filter = Me.OpenArgs        'this line is highlighted in debug
          Me.FilterOn = True
End If
OpenError_Resume:
Exit Sub

OpenError:
If Err.Number=2448 Then
   MsgBox "You must select a record before opening."
   Cancel=True
Else
   MsgBox Err.Number & Err.Description
End If
Resume OpenError_Resume
End Sub
0
 

Author Comment

by:BobNZ2
ID: 13510422
Thanks for the reply, inserted the code and first time I tried it I got another error this time in the form the user selects the record from...

Private Sub Command9_Click()
'Find a selected record
DoCmd.OpenForm "frmworksheet2", , , , , , "tblclient_jobnumber=" & " " & Me.listsearch.Column(1) & ""
    Forms!frmworksheet2.FilterOn = True                 'this line is highlighted in debug
    'close listsearch
    DoCmd.Close acForm, "frmlistsearch"
End Sub

when I tried it again so I could copy the error message nothing happened no error message (mine or access) the form just closed

B
0
 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 2000 total points
ID: 13510449
You probably need to change the above code to take into account whether the target form opens successfully or not:

Private Sub Command9_Click()
'Find a selected record
DoCmd.OpenForm "frmworksheet2", , , , , , "tblclient_jobnumber=" & " " & Me.listsearch.Column(1) & ""
If SysCmd(acSysCmdGetObjectState,acForm,"frmworksheet2")<>0 Then
    Forms!frmworksheet2.FilterOn = True
    'close listsearch
    DoCmd.Close acForm, "frmlistsearch"
End If
End Sub
0
 

Author Comment

by:BobNZ2
ID: 13510865
Thanks shanesuebsahakarn, I was getting another error 2501 but used the code you gave me for other form and trapped the error...

Private Sub Command9_Click()

    On Error GoTo OpenError:
'Find a selected record
DoCmd.OpenForm "frmworksheet2", , , , , , "tblclient_jobnumber=" & " " & Me.listsearch.Column(1) & ""
If SysCmd(acSysCmdGetObjectState, acForm, "frmworksheet2") <> 0 Then
    Forms!frmworksheet2.FilterOn = True
    'close listsearch
    DoCmd.Close acForm, "frmlistsearch"
End If
OpenError_Resume:
Exit Sub
OpenError:
If Err.Number = 2501 Then
   MsgBox "You must select a record before opening."
   'Cancel = True
Else
   MsgBox Err.Number & Err.Description
End If
Resume OpenError_Resume
End Sub

had to comment out the error message  from the other form as I was getting the same message twice, once from each form

everthing working aok now, thanks for the help.

B
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Implementing simple internal controls in the Microsoft Access application.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question