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

Matching list items

Status
Not open for further replies.

homesick

Programmer
Dec 5, 2001
55
CA
I have a Sales tracker form in VB6 that a user fills ( name,date, prod code, dollar..) I want to restrict the user from submitting this form unless a dollar amount is entered ( not all prod codes require dollar amounts).

How do i force the user to enter a dollar amount if they choose a product code that requires one?


 
The simplest way is to use if/else/endif, and a list of product codes that require dollars. For example:

private sub button_click()

if len(trim(name.txt)) > 0 and _
len(trim(date.txt)) > 0 and _
len(trim(prodcode.txt)) > 0 then
if instr(1,pc_with_dollar,prodcode.text) > 0 then
if len(trim(dollar.txt)) > 0 then
process data
else
name.tabstop = true
name.setfocus
exit sub
endif
else
process data
endif
else
name.tabstop = true
name.setfocus
exit sub
endif

end sub
 
John: how would i hide the button?


Here's what i have:


Private Sub command1_Click()

Dim tracker As ADODB.Recordset
Dim strAname As String
Dim strdate As String
Dim strcname As String
Dim strrnumber As String
Dim strcode As String
Dim strdollar As String
Dim strxcode As String
Dim strxdollar As String
Dim strx2code As String
Dim strx2dollar As String
Dim strx3code As String
Dim strx3dollar As String
Dim strcalltype As String
Dim strcomments As String
Dim strpd As String
Dim strrpc As String


Dim ssql As String
Set tracker = CreateObject("adodb.recordset")

tracker.ActiveConnection = "provider=microsoft.jet.oledb.3.51;Data Source=a:\tracker.mdb"
ssql = "select * from tracker"
tracker.Open ssql, , adOpenStatic, adLockOptimistic, adExecuteNoRecords And adCmdText


strAname = combo5.Text & ""
strdate = Text2.Text & ""
strcname = Text5.Text & ""
strrnumber = Text6.Text & ""
strcode = Combo1.Text & ""
strdollar = Text8.Text & ""
strxcode = Combo2.Text & ""
strxdollar = Text10.Text & ""
strx2code = Combo3.Text & ""
strx2dollar = Text12.Text & ""
strx3code = Combo4.Text & ""
strx3dollar = Text14.Text & ""
strcalltype = Combo6.Text & ""
strcomments = Text16.Text & ""
strpd = Text3.Text & ""
strrpc = Text4.Text & ""

If Combo1.Text = "MTG" Then
Command1.Visible = True
Else
Command1.Visible = False
End If

'proceed only if the user actually enters name, date, cx name, calltype
If strAname <> &quot;&quot; And strdate <> &quot;&quot; And strcalltype <> &quot;&quot; And strcname <> &quot;&quot; Then

tracker.AddNew
tracker(&quot;aname&quot;) = strAname
tracker(&quot;date&quot;) = strdate
tracker(&quot;cname&quot;) = strcname
tracker(&quot;rnumber&quot;) = strrnumber
tracker(&quot;code&quot;) = strcode
tracker(&quot;dollar&quot;) = strdollar
tracker(&quot;xcode&quot;) = strxcode
tracker(&quot;xdollar&quot;) = strxdollar
tracker(&quot;x2code&quot;) = strx2code
tracker(&quot;x2dollar&quot;) = strx2dollar
tracker(&quot;x3code&quot;) = strx3code
tracker(&quot;x3dollar&quot;) = strx3dollar
tracker(&quot;calltype&quot;) = strcalltype
tracker(&quot;comments&quot;) = strcomments
tracker(&quot;pd&quot;) = strpd
tracker(&quot;rpc&quot;) = strrpc
tracker.Update

MsgBox &quot;Record added&quot;, , &quot;Tracker&quot;
Else: MsgBox &quot;The mandatory fields(highlighted in RED)must be filled in before sumbmitting the tracker.&quot;, vbExclamation, &quot;Reminder&quot;

End If

End Sub
 
Vududoc:

You have to bear with me...i'm still kinda new to this..could you be more specific...above is my code..
 
Hi,
Here's a way to use a function:
Code:
Sub ShowButton()
' ...
' assign ProdCd & DolVal
' ...
    With UserForm1.CommandButton1
' - other comaand button attribute assignments
        .Enabled = ReadyToSubmit(ProdCd, DolVal)
    End With
End Sub
Function ReadyToSubmit(ProductCode, DollarValue) As Boolean
    Select Case ProductCode
        Case &quot;Product1&quot;, &quot;Product2&quot;, &quot;Product3&quot;
            If DollarValue > 0 Then
                ReadyToSubmit = True
                Exit Function
            End If
    End Select
    ReadyToSubmit = False
End Function
Skip,
metzgsk@voughtaircraft.com
 
Is the dollar amount entered into a textbox? If so, you could try this in the Change event:

--------------------
Private Sub txtDollarAmount_Change()
cmdSubmit.Enabled = txtDollarAmount.Text <> &quot;&quot;
End Sub

--------------------

This only checks that some value has been entered into the textbox. If you needed to you could use this same idea to use a function you write to verify a valid dollar amount has been entered:

Private Function IsValidDollarAmount(Value As Variant) As Boolean
Dim TestVal As Currency

If Value = &quot;&quot; Then
IsValidDollarAmount = False
Exit Function
End If

On Error Resume Next
TestVal = Value 'There may be a better way to make sure Value is a valid currency data type, this is just a quick example

IsValidDollarAmount = Err.Number = 0

On Error GoTo 0

End Function

Private Sub txtDollarAmount_Change()
cmdSubmit.Enabled = IsValidDollarAmount(txtDollarAmount.Text)

End Sub
------------------------

Good luck!

~Mike

Any man willing to sacrifice liberty for security deserves neither liberty nor security.

-Ben Franklin
 
It would seem to me that one additional field of information would be very helpful and that is a boolean field that indicates whether or not the product code requires a dollar amount or encode the product code so that you can easily determine if a dollar amount is needed. If that can done then that would solve most of your problem. If not then I think you will have to brute force it. Dan Grogan
dan@siqual.com

&quot;Absit prudentia nil rei publicae profitur.&quot;
Without common sense you ain't gonna have nothing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top