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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto Insert in memo field 2

Status
Not open for further replies.

niteraven

Technical User
Oct 26, 2006
92
US
Hello All,

I am trying to get some information to auto insert into a memo field BEFORE the user enters information. It works except now they want to choose if they want the info to insert before entering.
I added a msgbox to the code, and it works, but now if the memo field is null it puts the auto inserted text on the second line. (it is not checking for null)

Code:
  Dim msgresponse As VbMsgBoxResult
           
    msgresponse = MsgBox("DO YOU WANT TO ADD THE DATE INTO THE COMMENTS FIELD", vbQuestion + vbYesNo, "ADD DATE TO COMMENTS")
        
        If msgresponse = vbYes Then
           If Me.comments.Value = Null Then
                Me!comments = "NEW COMMENT: " & "-(" & Now() & ");"
           Else
                Me!comments = Me!comments & vbCrLf & "NEW COMMENT:" & "-(" & Now() & ");"
                Me.comments.SelStart = Nz(Len(Me.comments) + 2, 0)
           End If
        Else
           Me.comments.SelStart = Nz(Len(Me.comments) + 15, O)
            
        End If

ANy help would be appreciated!
Raven
 
Try

If IsNull(Me.comments) then
...


untested

HTH << MaZeWorX >> Remember amateurs built the ark - professionals built the Titanic [flush]
 
Hi Maze,

When i changed to isnull it skips right over that and goes to the else part of that if statement. I put a few breakpoints in to see where it was going in the code when the memo field was null.

Any other ideas?

THanks for your input!
Raven
 
Hiya Maze

This worked i am posting the code for others. The suggestion by Maze worked, i was deleting the comment in a test record, and access was seeing it as not null because of that. when i then saved the record and went back in it was working exactly as it should. I have learnt a very valuable lesson with this problem, it is a good day.

Code:
Dim msgresponse As VbMsgBoxResult
    
    
        
        msgresponse = MsgBox("DO YOU WANT TO ADD THE DATE INTO THE COMMENTS FIELD", vbQuestion + vbYesNo, "ADD DATE TO COMMENTS")
        If msgresponse = vbYes Then
           If IsNull(Me.comments) Then
                Me!comments = "NEW COMMENT: " & "-(" & Now() & ");"
                Me.comments.SelStart = Len(Me.comments) + 2
           Else
                Me!comments = Me!comments & vbCrLf & "NEW COMMENT:" & "-(" & Now() & ");"
                Me.comments.SelStart = Len(Me.comments) + 2
           End If
        Else
           Me.comments.SelStart = Len(Me.comments) + 15
            
        End If


thank you maze
Raven
 
A simpler way:
Code:
...
        If msgresponse = vbYes Then
            Me!comments = Me!comments + vbCrLf & "NEW COMMENT:" & "-(" & Now() & ");"
            Me!comments.SelStart = Len(Me.comments) + 2
        Else
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi Phv

I had that code and it added the new comment and date on the second line of the comments field. Which drove my users nuts. So i had to change to that code. I agree it is simpler that way.

Thanks!
Raven
 
Did you notice the + instead of & ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi PHV,

You are awesome! And thanks for pointing out the difference in the code! It works great!

Thanks!
Raven

(Have a star!)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top