Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro 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 March 12th, 2007, 10:49 PM
Registered User
 
Join Date: Mar 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Program Flow Interrupted By IF...THEN Statement

Hey there fellow programmers,

I've been working on a project for work that keeps a log of all of our telxon transactions. We do two things, Upload, and Update Telxons. I parse a log file into my table and based on certain values I determine whether it is an Update Transaction or Upload Transaction and process accordingly. I've set up another table that has all of the info for each individual telxon, as well as the last time it was uploaded. I've created an update query meant to edit the LastUpdate column when a specific telxon number is updated. This is the code for my "Information Needed" form...

Public Sub Form_Open(Cancel As Integer)
    Dim strOpenType As String
    strOpenType = Me.OpenArgs
    Me.tbConfirmationPreview.Value = strInfo

    If strOpenType = "Update" Then
        Me.Caption = "Information Needed - Update Transaction"
        tbCurLoadNum.Enabled = False
        tbCurLoadNum.Value = "0"
    ElseIf strOpenType = "Upload" Then
        Me.Caption = "Information Needed - Upload Transaction"
        tbCurLoadNum.Enabled = True
        tbCurLoadNum.Value = ""
    End If
End Sub

Private Sub cmdClose_Click()
    DoCmd.Close acForm, "Information Needed", acSaveNo
End Sub

Private Sub cmdOK_Click() //This is the problem section here

    If strOpenType = "Update" Then /Here
        DoCmd.OpenQuery "TelxonUpdate" /Here
    End If /Here

    intLoadNum = tbCurLoadNum.Value
    intTelxonNum = tbCurTelxonNum.Value
    DoCmd.Close acForm, "Information Needed", acSaveNo
End Sub

Private Sub tbCurTelxonNum_AfterUpdate()
    Call cmdOK_Click
End Sub

The text file gives me most of the criteria itself, but I ask the user for the telxon number and Load number becuase the file on the telxon doesn't have that information. From here the variables are passed to the global variables "intTelxonNum" and "intLoadNum" and a new record gets added through a function in a module file. Problem is, when that If Then statement is there, the values don't transfer into the variables and they don't get stored in the table. I cannot figure out why a simple Run Query statement would negate the function of these variables, but if I comment them out and run the code it works perfectly. Also, if I run the Update Query from the Query menu after the record addition, it operates correctly. Does anyone have any ideas on what I'm doing wrong? Your help is much appreciated!

DJ Quimby
 
Old March 13th, 2007, 07:18 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there...

what is that docmd?? is a function?? is a procedure?? is a class??

somebody is changing the values of that tbcurloadnum and the other one (by the way.. what are they??)

also why are you saving the values to global variables?? every time you can try to avoid global variables to pass data along the program..

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
 
Old March 13th, 2007, 12:41 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

docmd is an access database object that allows you to run Access actions or "macro" commands within an access application.

Woody Z
http://www.learntoprogramnow.com
How to use a forum to help solve problems
 
Old March 13th, 2007, 12:50 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

so this is no VB? it's VBA??

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
 
Old March 13th, 2007, 12:55 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Yes its VBA.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old March 13th, 2007, 04:15 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

It seems that an error is being raised before you get to
Code:
    intLoadNum = tbCurLoadNum.Value
I believe .OpenQuery performs the action of double-clicking the query name in the DB window.

If I remember right, there is an additional argument to make this a synchronous action (code halts until the query window is closed).

What is it that you want the opening of the query to do, that needs to be done as the step preceding the setting of the values of the variables? (I presume there is sequentiality here, since you have those actions in that order in your routine.)

I don't see anywhere where a new record gets added, as you described.

My guess is that what you want on the OK button click is (in pseudo-code):
Code:
Private Sub cmdOK_Click()

    Dim A_Recordset As Recordset

    If strOpenType = "Update" Then
        ' Open A_RecordSet
        ' Add a new record so it is the current record
        ' Fill the record’s Fields with the Data
        ' Update the recordset
        ' Close the recordset
    End If

    ' Save the values in variables
    intLoadNum = tbCurLoadNum.Value
    intTelxonNum = tbCurTelxonNum.Value
    DoCmd.Close acForm, "Information Needed", acSaveNo
End Sub
Does that seem right?
 
Old March 20th, 2007, 09:28 AM
Registered User
 
Join Date: Mar 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry for the delayed reposting... boss has been out of work for the past week, haven't had a chance to post... so, on to business...

Brian,
The "Information Needed" Form is called within a function based on a couple of variables. When the OK_Click is executed, the values entered are saved to the globals, intTelxonNumber and intLoadNumber. Then program flow returns to the "AddLine" function I wrote, which adds the entire row, including the requested information, to the table.
Now, about there being an issue before it gets to that section, here is the part I couldn't understand:
Like I said in the original post, the presence that IF...THEN statement makes zeros pass to those variables, but it happens whether the IF...THEN is above or below the variables. I used the same logic you seem to be thinking, but positioning didn't change anything.

If you or anyone else would like to see the entire file, I would be glad to send it to you. Be it that this is a workplace specific Access app, I can see that it could be very difficult to understand the scope of the project without seeing all of it.

DJ Quimby
 
Old March 20th, 2007, 05:06 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

It would be informative if you would adjust the sequence of statements to fill the variables before the If / Then statement:
Code:
Private Sub cmdOK_Click()

    intLoadNum = tbCurLoadNum.Value
    intTelxonNum = tbCurTelxonNum.Value

    If strOpenType = "Update" Then
        DoCmd.OpenQuery "TelxonUpdate"
    End If

    DoCmd.Close acForm, "Information Needed", acSaveNo
End Sub
Then put a breakpoint at intTelxonNum = . . .
Then, with the code halted, check the value of the variables.
If the values are something other than "" then single-step through the code, checking the value of the variables and the .Value properties of the objects from which the data are coming.

If, by the time you get to the End Sub statement the variables still have values, continue stepping so that you return to the calling routine still halted, and use the immediate window (or whatever) to again check the values.

Then come back here, and let's see what we have.
 
Old March 22nd, 2007, 07:57 AM
Registered User
 
Join Date: Mar 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I will give that a try tonight when I get to work. I'll admit, I don't fully grasp how to use the debugging tools at my disposal, but that sounds pretty straight forward. I'll repost tonight or tomorrow morning with the results.

DJ Quimby
 
Old March 23rd, 2007, 01:25 AM
Registered User
 
Join Date: Mar 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, I still don't have it figured out but I think we're a little closer. For one, I realized that whenever this code is run, by the time we get to the IF..THEN in question, the value of strOpenType is "0" because its scope is only as long as the Form_Open() function.

Question on scope before I continue: If a variable is defined within a function on a form, will it remain defined as long as the form is open, though it only holds its set value while the function using it is running? Otherwise, my second use of strOpenType should have produced an error because the variable wouldn't have been defined at all.

For now I remedied this simply by making it a global variable, as this won't affect any other program flow. While this fixes the problem where the value of the variable disappears, I can't explain why. The IF...THEN statement was failing every time. I stepped through to the end of the Subroutine, and intTelxonNum retained it's value the entire time.

The TelxonUpdate query still is not functioning. If I run it manually after all this code runs through, it will update the value, but won't update when executed in code.

DJ Quimby





Similar Threads
Thread Thread Starter Forum Replies Last Post
Flow chart of Cobol program in dotNet SOANS General .NET 0 November 20th, 2007 11:29 PM
Flow of the Program ? pandian Java Basics 2 March 20th, 2006 11:07 PM
weird program flow with nested functions zayasv General .NET 1 January 6th, 2006 11:06 AM
weird program flow with nested loops zayasv Intro Programming 2 November 17th, 2005 06:19 AM
weird program flow with nested functions zayasv VB.NET 0 October 26th, 2005 11:17 AM





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