Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 24th, 2006, 10:13 AM
Registered User
 
Join Date: Aug 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default removing Null values from linkcriteria

I have 4 textboxes for users to enter data and then search a database for those 4 criteria. However I don't know how to remove a criteria if the user does not fill it in. Here is the linkcriteria i am using, it works when all the criteria is provided:

    stLinkCriteria = "[SLA Number]=" & "'" & varHIN & "'" & " And " & "[RO Number]=" & "'" & varRO & "'" & " And " & "[ISS Contact]=" & "'" & varISS & "'" & "And " & "[Client Name]=" & "'" & varClient & "'"

I tried an "IF IsNull" statement, but that would require putting data for each combination of Null and non-Null values for the 4 criteria.

Is there a wildcard function in vb? I was thinking I could assign that to a criteria if there was a null value there.

Essentially i'd like a statement like this (1, 2, 3, 4 are variables):

stlinkcriteria = 1 and 2 and 3 and 4
ONLY IF 1, 2, 3, 4 are NOT null values.

 
Old August 24th, 2006, 12:25 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Create an array of strings for each criterion, or a separate variable for each criterion.
If the textbox for a given criterion is empty, do nothing. (Strings initialize to "".)

Then just concatenate them all in your statement:
Code:
    stLinkCriteria = Var1 & var2 & var3 & var4
    ' Or
    stLinkCriteria = Var(1) & var(2) & var(3) & var(4)


Alternately, you could have 4 If statements, each of which contributes one criterion only if the textbox for that criterion is not empty.
 
Old August 25th, 2006, 08:08 AM
Registered User
 
Join Date: Aug 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply, i'm not 100% sure how to do what you said, here is my attempt:

    Dim stHIN As String 'variable assigned to criteria 1

    If Me.txtHIN <> "" Then
        varHIN = Me.txtHIN
    End If


I had one of those for each criteria, didn't work though. Maybe i'm not joining the variables correctly:

    stLinkCriteria = "[SLA Number]=" & "'" & stHIN & "'" & " and " & "[RO Number]=" & "'" & stRO & "'" & " and " & "[ISS Contact]=" & "'" & stISS & "'" & " and " & "[Client Name]=" & "'" & stClient & "'"

I can bring up the correct record using the above line as long as ALL the variables are there, as soon as one is missing the record cannot be found.

thanks

 
Old August 29th, 2006, 01:19 PM
Registered User
 
Join Date: Aug 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Still unable to figure this out, any help would be greatly appreciated.

4 text boxes
user enters data, then clicks button to search records
based on the 4 text boxes, records are shown in a seperate form

everything works as long as ALL 4 text boxes are filled...i want to basically bypass a text box from being included in the "linkcriteria" command if it is empty...

thanks.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Null values jmcgranahan BOOK: Access 2003 VBA Programmer's Reference 0 August 29th, 2006 02:25 PM
null values for properties polofson .NET Framework 2.0 1 April 23rd, 2006 05:33 AM
CheckBoxList and Null Values steve35719 ASP.NET 2.0 Basics 1 April 21st, 2006 09:42 AM
Parsing and Removing CSV values in row cell. peryan77 SQL Server 2000 5 February 2nd, 2006 03:48 PM
Handling Null Values nvenkat75 ADO.NET 2 January 16th, 2006 05:46 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.