Results 1 to 2 of 2
  1. #1
    Baldeagle is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2011
    Location
    Northern Ireland
    Posts
    136

    Visual Basic Code for If Else

    I am pretty competent with 'normal' database development but am not competent with Visual Basic!


    I have a form (Ledger) with a sub-form (Sub-ledger) where I enter details of money received for a charity and then (in the sub-ledger) the allocation of the gift to a number of Missions. The fields in the sub-form are Sub-Ledger Number, Ledger Number, Amount, Society, Full Name (Exc Prefix) and Instructions.
    When a code is entered in the Society field and the tab key is pressed the following field 'Full Name (exc Prefix)' is populated from an existing table. The focus moves directly to the Instructions field. I want to highlight a situation where a code is entered which does not have an existing record in the table in my database. I was trying, unsuccessfully, to use VB in the Instructions field (On Got Focus) to throw up a message drawing attention to the error and then run an existing query which would list the details for all existing Societies. I tried to get the code to interrupt the entering of data where the 'Full Name (Exc Prefix)' was null but my VB skills are not up to it!! The source of the information in the sub-form (described above) is a query called 'Link Sub-Ledger to Mission Names' so I want a message box to open followed by the Table containing all the Missions details (called Missions). If the field is not null I want to be able to continue entering data in the Instructions field.

    Can someone please help me with this?

  2. #2
    Baldeagle is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2011
    Location
    Northern Ireland
    Posts
    136
    I have solved the above myself!! I have used the following code which does what I want.

    Private Sub Instructions_GotFocus()

    Dim stDocName As String
    stDocName = "Missions without Matching Sub-Ledger"
    If IsNull([Full Name (Exc Prefix)]) Then MsgBox "Check the code you have entered."
    If IsNull([Full Name (Exc Prefix)]) Then DoCmd.OpenQuery stDocName, acNormal, acEdit

    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Using Access Instead of Visual Basic
    By dinz in forum Programming
    Replies: 2
    Last Post: 12-19-2019, 10:33 AM
  2. Visual Basic
    By kwooten in forum Queries
    Replies: 2
    Last Post: 01-25-2012, 08:22 AM
  3. how to use visual basic in access
    By learning_graccess in forum Access
    Replies: 3
    Last Post: 12-05-2011, 03:23 PM
  4. Replies: 1
    Last Post: 06-29-2011, 07:22 AM
  5. Can't see visual basic code
    By Michele Keck in forum Forms
    Replies: 5
    Last Post: 09-29-2010, 11:31 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums