Results 1 to 7 of 7

Thread: variables in select statements

  1. #1
    Guest

    Red face

    I have two forms, I declare a variable as public in the general decleration. In one form I give that variable a value, in the second form I have a select statment using that variable, but it doesn't hold the value. EX: Public phase as string......phase="PRI"...."Select unit from table where ph=phase"

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Public in a form pertains to all within that form.
    Public in a .bas module is across all forms.

    Or
    Public in a form like this.

    Form2.text1 = form1.myVariable

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    Guest
    I did put my public statement in the .bas module. In my second form I have something like(phhold=form1.myvar) that works, when I debug the value is there. But on my select statement it doesn't. I got an error messageinvalid column name. If I hard code it in my select statement it works. Maybe my syntex is off, could someone show me how they would write the select statment using the variable in the where clause...THANX

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    easiest if you post your code so one can see what is happening.
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  5. #5
    Guest
    Your sql statement needs to look somthing like this:

    "Select unit from table where ph=" & phase

    If phase is a string, do this:

    "Select unit from table where ph='" & phase & "'"

    Hope it works...

  6. #6
    Guest
    Module (module.bas)
    (general) (declarations)
    Public phasehold as string
    ***************************
    FrmMain
    (mnuprimary) (click)
    phasehold="Pri"
    ********************************
    form2
    Public Sub Form_Load()
    Dim phhold As String
    Dim sphase As String
    Dim ssql As String
    phhold = phasehold (phhold does show "pri" as its value)
    Adodc1.Refresh

    ssql = "select unit from units where units.phase = phhold"
    Adodc1.CommandType = adCmdText
    Adodc1.RecordSource = ssql
    Adodc1.Refresh

    Dim texttotal As Double

    End Sub

  7. #7
    Guest
    DeepestDish
    Thanks that was it, I didn't have the right syntex for the variable in the statement.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width