Run Time Error

kbreiss

Registered User.
Local time
Today, 03:39
Joined
Oct 1, 2002
Messages
228
I have a combo box that looks up information based on what was selected in the combo box. If there is nothing in the table (Which is likely, b/c it is an appointment scheduler and appointments get deleted once they are past the current date) I receive a run time error 3021; No current record. The only way I have found around this is to put in an example appointment so there is at least one record in the table with an appointment date far in the future.

Is there any way that it will just show nothing if nothing is in that table?

Thanks in advance,

Kacy
________
Gm Foods
 
Last edited:
You need to trap for the #3021 error in the after update event of your combo box...
Code:
Private Sub cbAppointment_AfterUpdate()
On Error GoTo Err_cbAppointment_AfterUpdate
    
'your code here, if needed...
    
[b]Exit_cbAppointment_AfterUpdate:
    Exit Sub[/b]
    
Err_cbAppointment_AfterUpdate:
    If Err = 3021 Then  'No current record
        MsgBox "No records found!", vbInformation, "Zilch!"
        Exit Sub
    Else
        MsgBox Err.Number & " - " & Err.Description
        Resume Exit_cbAppointment_AfterUpdate
    End If
    
End Sub
HTH
 
Last edited:
ghudson,
Ok, Here's what I got. I have a macro running on the AfterUpdate. So is it all right to put the code you supplied in the "On Change" I tried the following code below and I am receiving a compile error that says Label not defined. When I check the code it is highlighting the "Resume Exit_Combo12_Change. Do you have any idea what I am doin wrong. Thanks very much.

Private Sub Combo12_Change()
On Error GoTo Err_Combo12_Change

'your code here, if needed...

Err_Combo12_Change:
If Err = 3021 Then 'No current record
MsgBox "No records found!", vbInformation, "Zilch!"
Exit Sub
Else
MsgBox Err.Number & " - " & Err.Description
Resume Exit_Combo12_Change
End If

End Sub

Thanks again,
Kacy
________
Cat wheel
 
Last edited:
Sorry, I forgot a piece of the error code.

Check out the bolded section in my previous post above.

I suggest that you keep everything in the AfterUpdate event. Just order your code by what you want to run first. If you are really using a macro...why? Convert the macro to code. You can not trap for errors with macros.

HTH
 
ghudson,
I'm still receiveng the runtime error 3021 when there are no records. I put the code you supplied as the first thing to run in the AfterUpdate event. The debugger is highlighting what I have highlighted below. As for as running macros.....you would probablly have a stroke if you new how many macros I run. I'm not familiar with VB or really any coding for that matter. Do you have any suggestions on books, etc to wing me off macros and start writting more code in Access? Besides being able to do more by writting code what are some other advantages against macros? Thanks!

Private Sub cbAppointment_AfterUpdate()
On Error GoTo Err_cbAppointment_AfterUpdate

'your code here, if needed...

Exit_cbAppointment_AfterUpdate:
Exit Sub

Err_cbAppointment_AfterUpdate:
If Err = 3021 Then 'No current record
MsgBox "No records found!", vbInformation, "Zilch!"
Exit Sub
Else
MsgBox Err.Number & " - " & Err.Description
Resume Exit_cbAppointment_AfterUpdate
End If

End Sub


Private Sub Combo12_AfterUpdate()
' Find the record that matches the control.
Me.RecordsetClone.FindFirst "[APPOINTMENT].[FAC_ID] = '" & Me![Combo12] & "'"
Me.Bookmark = Me.RecordsetClone.Bookmark
End Sub

Thanks,
Kacy
________
Zoloft Lawyer
 
Last edited:
Looks like you are trapping for the error in the cbAppointment_AfterUpdate() but not in the Combo12_AfterUpdate(), where you are actually getting the error. Appply the same method of error trapping in the Combo12_AfterUpdate().

About the macros question, there are only two macros that I personally think a programmer would ever consider using, AutoExec and AutoKeys.

The first step for you would be to convert your macros to VBA and see how that works. Take small steps, experiement and keep posting when you have problems. Use the built-in Help files for Microsoft did a great job with the Access help files. I have never read a VBA book so I can not offer any advice.

HTH
 
Thanks for the advice.....One more question. How to you convert macros to VBA?

Thanks,
Kacy
________
Blonde Latina
 
Last edited:
I suggest that you make a copy of your form when converting the macros to code. From the copied form, ensure that all of your macros that you want to convert have been assigned to a command button.

Open the copied form in the Design view.

From the menu bar, click these options...

Tools / Macro / Convert Forms Macros To Visual Basic

Ensure all options are checked before your click CONVERT.

Good luck!
 
Hi Kacy.

I am new to this forum and relatively new to Access. (I can't even find how to create a new thread!) You are the only person as far as I can see that has mentioned and appointment scheduler recently, so I thought you'd be the person to ask. I have created a database for my clients and a form to search for a particular record by enterting personal details. I am one of four adviser that work with our clients. I want to create an appointment scheduler as part of the database. We have recently had problems with admin. double-booking appointments because they are using an antiquated manual system. I, like a fool offered to try to create a solution. I think I may have been a little too ambitious. For this part of the project I have not got a clue where to start, If you or anyone else reading this post can't help I would be extremely greatful.

T h a n k y o u.
 
As far as an appointment scheduler......and double booking....I still haven't found a good way to control that. In fact my company is looking for an appoinment scheduling software that will take care of this problem. Right now I have a button users can click on called "verify appointments" that will run a query and list any appointments that were double booked. I'm sorry I can't be of much help....I struggled w/ this for a long time and still do not have a good solution. There are many helpful people in this forum that are very knowlegable......just post a question and you will be sure to get some good advice. Good Luck.

Kacy
________
IPAD ACCESSORIES
 
Last edited:

Users who are viewing this thread

Back
Top Bottom