Wrox Programmer Forums
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics 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 June 24th, 2004, 04:27 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Default Please help...

Hello everybody... I`m experiencing a problem... I have a table with 4 fields (user_id, language, grade, rec_id) in my db. Language is part of the primary key, so it cannot by a null value in this field.
As you can see below I`m do not permit this using VB script. So... If someone will try to insert a null value a warning message comes on the screen, but the action keeps to go on. So I have an error screen coming from Microsoft Access that informs me about the null values... and so.

I would like you to tell me what to do with the VB script in order to stop the action when "Language field" is empty.

Here is the code of the hole page I use.

<BODY>
<%

    'Create the recordset object
    Set objRS = Server.CreateObject("ADODB.Recordset")

    'Set the SQL string
    strSQL = "Select user_id, Language, Grade, rec_id from Languages Where rec_id = " & _
        Request.Form("recid")

    objRS.Open strSQL, "dsn=My_proj"
%>

<form action=UpdateLanguage2.asp method=post name=frmUpdate>
    <input type=hidden name=Action value=Update>
    <input type=hidden name=txtID
        value=<%=Request.Form("recid")%>>
    <table>
        <tr>
        <td nowrap>Language</td>
        <td><input type=text name=txtlanguage size=20
                value="<%=objRS("Language")%>">*</td>
        <td width=10></td>
        <tr>
        <td>Grade</td>
        <td><select name=txtgrade>
        <option value="<%=objRS("Grade")%>" selected> <%=objRS("Grade")%> </option>

        <%if objRS("Grade")="Good" then%>
        <option value="Pretty good">Pretty good</option>
        <option value="Great">Great</option>

        <%elseif objRS("Grade")="Pretty good" then%>
        <option value="Good">Good</option>
        <option value="Great">Great</option>

        <%elseif objRS("Grade")="Great" then%>
        <option value="Good">Good</option>
        <option value="Pretty good">Pretty good</option>
<%
end if
%>
        </tr>
    <tr>
        <td><input type=submit name=btnSubmit value=Submit></td>
        </tr>

    </table>
</form>

<script language=vbscript>
Sub btnSubmit_OnClick()

        If Len(frmupdate.txtlanguage.value) = 0 Then
        Alert "You have to insert a Language"
        frmupdate.txtlanguage.focus
        Exit Sub
    End If

    Call frmupdate.submit()
End Sub
</script>

<%
        'Close and dereference database objects
        objRS.Close
        Set objRS = Nothing


%>

</BODY>
 
Old July 7th, 2004, 11:07 PM
Authorized User
 
Join Date: Jul 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

First off, if your message "You have to insert a Language" doesn't show up then it means that the entry for language is valid. if so, you should try this,

If Len(Trim(frmupdate.txtlanguage.value)) = 0 Then
        Alert "You have to insert a Language"
        frmupdate.txtlanguage.focus
        Exit Sub
    End If

 
Old July 9th, 2004, 05:32 AM
Authorized User
 
Join Date: Jul 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to jhawar
Default

 If Len(frmupdate.txtlanguage.value) = 0 Then
        Alert "You have to insert a Language"
        frmupdate.txtlanguage.focus
        Exit Sub
else
Call frmupdate.submit()
    End If

hope this helps


Amit Jhawar
Developer
 
Old July 9th, 2004, 05:37 AM
Authorized User
 
Join Date: Jul 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to jhawar
Default

Sorry Half Answer
Instead of assiging the btnSubmit as type=Submit
say
<input type=button name=btnSubmit value=Submit>

Amit Jhawar
Developer
 
Old July 12th, 2004, 12:06 AM
Authorized User
 
Join Date: Jul 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yes, still, there's no difference with what your code does. i think you should take note that you should use trim. input with a space or lot of spaces for that matter will not give you a zero length string. ;)

 
Old July 14th, 2004, 06:10 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you guyz for your help...

The golden prize goes to Jhawar Amit. I changed the type into "button" and now it works!!! :)
Thank all of you who tried to help me! I hope that I`ll be able to help you... one day!









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