Function not working correctly

lcook1974

Registered User.
Local time
Today, 06:25
Joined
Dec 21, 2007
Messages
330
Hi all,
I am having an issue trying to debug this function. I downloaded a database from Microsoft and I am trying to implement into another database I am creating. This DB works okay but it isn't showing the correct date on the "frmInputBox".

There is a varible named "mynum" that is in the event "OnLoad" on the frmCalendar. This varible is referenced in the Module "modCalendar" but I can't for the life of my first born figure out why this varible isn't showing the correct date for the box selected.

I've attached a copy of the DB here so you can open and see for your self.

I am very very new to VBA and modules and avoid them like the plague if I can but I really like this feature and would love to use it and learn why and how one of you genius' fixed it.

The OnLoad event:
Code:
Private Sub Form_Load()
    Dim i As Integer, j As Integer
    Dim mycontrol As Control
    Dim strYear As String, nextYear As String
    Dim f As Form
    Dim mynum
        
    Set f = Forms!frmCalendar
    
    For i = 1 To 37
        Forms!frmCalendar!("Text" & i).Visible = False
        Forms!frmCalendar!("Day" & i).Visible = False
    Next
    
    'Set mycontrol = Me.Year
    j = 1990
    
    strYear = j
    
    For i = 1 To 60
        nextYear = j + i
        strYear = strYear & ";" & nextYear
        'Me.Year.AddItem j + i
    Next i
    
    Me.year.RowSource = strYear
    Me!month = Format(Now, "m")
    Me!year = Format(Now, "yyyy")
    Call Cal([month], [year])
    
End Sub

The function:
Code:
Function SendToInputBox(mynum)
    Dim f As Form
    Dim g As String
    
    Set f = Forms!frmCalendar
    g = Format(f("Date" & mynum), "dddd mmmm d, yyyy")
    
    DoCmd.OpenForm "frmInputBox"
    
    With Forms!frmInputBox
        !InputDay = mynum
        !InputDate = f("Date" & mynum)
        !InputFor = g
        !original_text = f("Text" & mynum)
        !InputText = f("Text" & mynum)
        !InputText.SetFocus
    End With
    
    SendKeys "{F2}^{HOME}", False
    
End Function


Any help would be great!
Larry
 

Attachments

I see

Dim mynum

But I do not see it being used anywhere - so it isn't being assigned a date.
 
It is somehow "supposed" to be used in the Function send to inputform...but I don't know what mynum is supposed to be.

if you click on a calendar box it pops up with a January date...Where is that date coming from?
 
I think you're getting confused on what gets sent and what gets declared where.

This function:

Function SendToInputBox(mynum)

uses mynum, and mynum is actually being declared there although it isn't being Typed and so it is a variant. Normally you would see something like

Function SendToInputBox(mynum As Date)

but I guess they did it this way to avoid problems with nulls.

So, you do not need to Declare Dim mynum in the other form function/sub. It is just passed by reference when the function gets called by using:

=SendToInputBox(9)

for example in the event properties dialog.
 
So why would it then put a January date in the table and show a January date in the unbound field of the input box?

and you're right...I am confused! :)
 
Bob Thanks for the help and understanding my confusion.... :)

I found an updated version on here from the creator...and it seems to be working fine.

Thank you again!! You are on of the best teachers I've had on MS Access!

Larry
 

Users who are viewing this thread

Back
Top Bottom