?
Solved

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

Posted on 2005-03-10
4
Medium Priority
?
338 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

771 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