Mandatory field and pop up message

Author Message
peelola

  • Total Posts : 1
  • Scores: 0
  • Reward points : 0
  • Joined: 7/16/2007
  • Status: offline
Mandatory field and pop up message Monday, July 16, 2007 2:18 PM (permalink)
0
Hi

I have been asked to look at an access database and try and add a mandatory field. I though it would be easy as having done ASP things in the distance past and played around with Access databases it thought it would be an easy job, but I can't for the life of me find out how to make it work.

There are 4 fields and the company field needs to be mandatory so that when someone clicks the visitor pass print button a message pops up if they haven't entered anything in the company field. I have no idea where to start with this and can't find anyone to help, finding knowledgeable people here in NZ for this stuff isn't easy! Anyway details below.

Option Compare Database


Private Sub cmdPrintPass_Click()
Dim Name            As String
Dim Company         As String
Dim RegNo           As String
Dim HostName        As String
Dim InDate          As String
Dim InTime          As String

    Name = IIf(IsNull(txtName), " ", txtName)
    Company = IIf(IsNull(txtCompany), " ", txtCompany)
    RegNo = IIf(IsNull(txtRegNo), " ", txtRegNo)
    HostName = IIf(IsNull(txtHostName), " ", txtHostName)
    InDate = CDate(Date)
    InTime = CDate(Time)
   
    lFnInsertIntoVisitor Name, Company, RegNo, HostName, InDate, InTime
   
    DoCmd.OpenReport "rptVisitorPass", acViewNormal
   
    'Rhonda asked to take off the second page of the label 16/07/2004
    'DoCmd.OpenReport "rptVisitorPolicy", acViewNormal
   
    lFnNextCustomer
   
End Sub
Private Sub lFnNextCustomer()
    DoCmd.Close acForm, "frmSignIn"
    DoCmd.OpenForm "frmSignIn"
End Sub
Private Sub lFnInsertIntoVisitor(Name As String, Company As String, RegNo As String, HostName As String, InDate As String, InTime As String)
Dim MyDb            As Database
Dim MyRec           As Object
    Set MyDb = CurrentDb
    Set MyRec = MyDb.OpenRecordset("Visitor")
    With MyRec
        .AddNew
        .Fields("Name") = Name
        .Fields("Company") = Company
        .Fields("CarRegNo") = RegNo
        .Fields("HostName") = HostName
        .Fields("InDate") = InDate
        .Fields("InTime") = InTime
        .Update
        .MoveLast
        txtVisitorNO = .Fields(0).Value
    End With
End Sub

Private Sub cmdSignInClose_Click()
    DoCmd.Close acForm, "frmSignIn"
End Sub

Private Sub Form_Open(Cancel As Integer)
    DoCmd.Maximize
End Sub
 
#1
    dm_4ever

    • Total Posts : 3687
    • Scores: 82
    • Reward points : 0
    • Joined: 6/29/2006
    • Location: Orange County, California
    • Status: offline
    RE: Mandatory field and pop up message Tuesday, July 17, 2007 2:10 AM (permalink)
    0
    This is VBA and not VBScript, but perhaps someone here may be able to provide some guidance for you.
    dm_4ever

    My philosophy: K.I.S.S - Keep It Simple Stupid
    Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
    Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
     
    #2
      ehvbs

      • Total Posts : 3320
      • Scores: 110
      • Reward points : 0
      • Joined: 6/22/2005
      • Location: Germany
      • Status: offline
      RE: Mandatory field and pop up message Thursday, July 19, 2007 12:40 PM (permalink)
      0
      Hi peelola,

      quick, dirty, and not tested:

         Company = IIf(IsNull(txtCompany), " ", txtCompany)
         RegNo = IIf(IsNull(txtRegNo), " ", txtRegNo)
         HostName = IIf(IsNull(txtHostName), " ", txtHostName)
         InDate = CDate(Date)
         InTime = CDate(Time)

         If "" = Trim( Company ) Then  ' nix in txtCompany
             MsgBox "Please enter company."
             Exit Sub
         End If
        
         lFnInsertIntoVisitor Name, Company, RegNo, HostName, InDate, InTime
        
      Good luck!

      ehvbs


       
      #3

        Online Bookmarks Sharing: Share/Bookmark

        Jump to:

        Current active users

        There are 0 members and 1 guests.

        Icon Legend and Permission

        • New Messages
        • No New Messages
        • Hot Topic w/ New Messages
        • Hot Topic w/o New Messages
        • Locked w/ New Messages
        • Locked w/o New Messages
        • Read Message
        • Post New Thread
        • Reply to message
        • Post New Poll
        • Submit Vote
        • Post reward post
        • Delete my own posts
        • Delete my own threads
        • Rate post

        2000-2012 ASPPlayground.NET Forum Version 3.9