Results 1 to 2 of 2
  1. #1
    shabbaranks is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Posts
    162

    How to determine if textbox contains a value then

    Hi Guys,

    Im trying to adapt my code to work so that if the textboxes contain a value then use the values within a query and if they dont then ignore the boxes and carry on. How would I go about this? Would it be done by using some kind of not null statement? Im kinda guessing so help is appreciated.



    Current code is below:
    Code:
    Option Compare Database
    
    Private Sub TotalHoursOk_btn_Click()
    Dim sProjectRef As String
    Dim sTotalhours As String
    Dim MySQL As String
    Dim sGroupID As Integer
    Dim sUserID As String
    Dim sUser As String
    sUser = Me.CurrentUser
    sUserID = "Forms![TimesheetForm]![LoggedInUser]"
    sGroupID = DLookup("DepGroupID", "UserNames_tbl", "[sUser]=" & sUserID)
    If Me.StartDate_totalhours_txtbox And Me.EndDate_totalhours_txtbox = Null Then
    If Me.ProjectRef_txtbox = "" Or IsNull(Me.ProjectRef_txtbox) Then
    MsgBox "Please Enter a Project Number"
    Else
    If Me.TotalHours_Combo = "" Or IsNull(Me.TotalHours_Combo) Then
    MsgBox "Please Select from the drop down list"
    End If
    Select Case Me.TotalHours_Combo
    Case "All Employees"
        If sGroupID = "2" Then
        MySQL = "Select * From TimesheetTable WHERE [ProjectRef] LIKE '*" & Me.ProjectRef_txtbox & "*'"
        QDef (MySQL)
    Else
        MsgBox "You are only allowed to query your own hours, change your selection to current user", vbInformation
    End If
        Me.TotalHours_Combo.SetFocus
        
    Case "Current User"
        MySQL = "Select * From TimesheetTable WHERE [ProjectRef] LIKE '*" & Me.ProjectRef_txtbox & "*' AND [sUser]=sUser"
        QDef (MySQL)
    End Select
    End If
    Else
    'Do I then repeat the steps if the values are not null? Or am I going about it incorrectly?
    End Sub
    Thanks

  2. #2
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    A quick check (to include both null and empty strings) for a text box (or combo for that matter) is:
    Code:
    If Len(Me.ControlNameHere & vbNullString) = 0 Then
       ' we don't have anything
    End If

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

Similar Threads

  1. Replies: 6
    Last Post: 10-03-2011, 12:51 PM
  2. Replies: 2
    Last Post: 05-26-2011, 12:15 PM
  3. Date range to determine rate
    By KevinMCB in forum Queries
    Replies: 5
    Last Post: 01-18-2011, 08:41 AM
  4. Using the date to determine if something was late.
    By lyrikkmashairi in forum Access
    Replies: 3
    Last Post: 11-02-2010, 10:59 AM
  5. How do I determine a SQL query result?
    By Trainman in forum Database Design
    Replies: 1
    Last Post: 10-15-2009, 04:49 AM

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