Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

run time error tied to module?

Status
Not open for further replies.

officemanager2

Technical User
Oct 11, 2007
116
CA
Hi there: I'm trying to get Allen Browne's calender to open from the yes button on a message box:
Code:
    Answer = MsgBox("Would you like to open the calender to set a date for call back?.", vbYesNo)

        If Answer = vbYes Then
            
        DoCmd.OpenModule "ajbCalender", "CalendarFor"
            
        Else
When set up this way I get run time error 2516 that the Db cannot find the module. Either I've written the code wrong, or I'm way off base in how I've set this up. The Calender is working from another button just fine, but I cannot get it to open from this button.

Any suggestions?
 

Make sure your module and function names are different.

Randy
 
I have never seen an openmodule used and can not think of any possible reason to use it.

Call ajbCalendar.CalendarFor(Me.someDateControl, "Enter Start Date")
 
I tried dropping the function name but the problem remains. I'll try what you recommend and see what happens.
 
Randy7000: I tried renaming and there was no affect, so I changed the name back and tried MajP's suggetion

MajP: I tried your suggestion and get a compile error - variable not defined and the module name (abjCalender) is highlighted

Code:
    Answer = MsgBox("Would you like to open the calender to set a date for call back?.", vbYesNo)
        If Answer = vbYes Then
            
        Call ajbCalendar.CalendarFor([txtStartDate], "Set the start date")
            
        Else

 
I assume you now have renamed the module. Since it is public just

Call CalendarFor([txtStartDate], "Set the start date")

 
At this time the module is still named ajbCalender. I did change the name but there was no affect from that change.

I've tried the code you have there but still the same error.

With the current line you have provided the error is now 2465 with the line that the db cannot find the '|' field.

Here is all the code, perhaps my mistake is somewhere else?

Code:
Public Sub cmdSave_Click()
    Dim ThisDB As DAO.Database
    Dim rstNotes As DAO.Recordset
    Dim Answer As String
    
    
    Set ThisDB = CurrentDb()
    Set rstNotes = ThisDB.OpenRecordset("Notes", dbOpenDynaset)
    
    With rstNotes
        .AddNew
            !ParentRecordID = Forms![MailingList]!ID
            !DateTimeStamp = date
            !Notes = Me.txtNoteText.Value
        .Update
    End With
    
    'initial message box
    
    Answer = MsgBox("Would you like to open the calender to set a date for call back?.", vbYesNo)
        If Answer = vbYes Then
            
        Call CalendarFor([txtStartDate], "Set the start date")
            
        Else
      'next message box
            
    Answer = MsgBox("Are you sure you don't want to enter a call back date?.", vbYesNo)
        If Answer = vbYes Then
                
        Call CalendarFor([txtStartDate], "Set the start date")
        
        Else
        End If

        End If
    


    rstNotes.Close
    ThisDB.Close
    
    Set rstNotes = Nothing
    Set ThisDB = Nothing
    
    Forms![MailingList]![Notes subform].Requery
    
    DoCmd.Close acForm, Me.Name

    

End Sub
 
Here is the function you are trying to call.
Code:
Public Function CalendarFor(txt As TextBox, Optional strTitle As String)
'On Error GoTo Err_Handler
    'Purpose:   Open the calendar form, identifying the text box to return the date to.
    'Arguments: txt = the text box to return the date to.
    '           strTitle = the caption for the calendar form (passed in OpenArgs).
    
    Set gtxtCalTarget = txt
    DoCmd.OpenForm "frmCalendar", windowmode:=acDialog, OpenArgs:=strTitle
    
Exit_Handler:
    Exit Function

Err_Handler:
    MsgBox "Error " & Err.Number & " - " & Err.Description, vbExclamation, "CalendarFor()"
    Resume Exit_Handler
End Function

The first parameter better be a reference to legitimate text box or this thing fails.

I am going to bet
txtStartDate
is not a reference to a text box from where you are calling it.


 
You are probably correct, any suggestions as to how I could go about correcting this?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top