Results 1 to 7 of 7
  1. #1
    Join Date
    May 2002
    Posts
    395

    Unanswered: Help on syntax in passing value of the string variable

    I would like to concatenate a string and pass a value of a string variable in the MsgBox but I¡¯m having trouble with the syntax in getting the value of the string

    Dim strMsg As String
    Dim response As Integer
    Dim fldval As String

    strMsg = "The Number of " & " & fldval & " & " is missing. Please enter a value." & Chr(10)

    If (Not IsNull([Production Sheet Sub 1].Form![Part Number])) And IsNull([Production Sheet Sub 1].Form![Cycles]) Then
    fldval = "Cycles"

    end if

    Thank you.

  2. #2
    Join Date
    Oct 2002
    Posts
    61

    Re: Help on syntax in passing value of the string variable

    Please explain what you are trying to accomplish with this vba procedure. I am a little confused because you are writting a value to a string variable (fldval = "Cycles") but you don't seem to be utilizing it in your proc.

  3. #3
    Join Date
    Dec 2002
    Posts
    60

    Re: Help on syntax in passing value of the string variable

    Not sure what you are doing, but looks like you had a few extra quotes and &'s. This might work:

    strMsg = "The Number of " & fldval & " is missing. Please enter a value." & Chr(10)

  4. #4
    Join Date
    May 2002
    Posts
    395

    SQL string

    I got the syntax working. However the SQL string won't give me the fldval("Cycles") where it is at. It displays "The Number of is missing. Please enter a value." If I place the same line of code after fldval = "Cycles" in IF statement it will give me the fldval.
    But I need the SQL string to be outside of the If statement so it can be reuseable. Is it somehow the fldval is not being passed?


    This is my code:

    Private Sub Production_Sheet_Sub_Exit(Cancel As Integer)
    Dim strMsg As String
    Dim response As Integer
    Dim fldval As String

    strMsg = "The Number of " & fldval & " is missing. Please enter a value." & Chr(10)

    If (Not IsNull(Me![Production Sheet Sub 1].Form![Part Number])) And IsNull(Me![Production Sheet Sub 1].Form![Cycles]) Then
    fldval = "Cycles"
    'strMsg = "The Number of " & fldval & " is missing. Please enter a value." & Chr(10)
    response = MsgBox(strMsg, vbYesNo)
    If response = vbYes Then
    'Me![Production Sheet Sub 1].Form![Cycles].SetFocus
    'DoCmd.GoToControl ("[Cycles]")
    End If

    End If


    End Sub

    Thank you!!

  5. #5
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    I'm quite a newbie at VB, so take my advice with caution hehe..

    That said, have you considered declaring the var as a global? If I understand correctly, that would make it constant throught the statement...

  6. #6
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    Private Sub Production_Sheet_Sub_Exit(Cancel As Integer)
    Dim strMsg As String
    Dim response As Integer
    Dim fldval As String

    strMsg = "The Number of " & fldval & " is missing. Please enter a value." & Chr(10)
    'you set strMsg here, but fldval is empty: comment the above line

    If (Not IsNull(Me![Production Sheet Sub 1].Form![Part Number])) And IsNull(Me![Production Sheet Sub 1].Form![Cycles]) Then
    fldval = "Cycles"
    'and uncomment the next line: fldval is now defined
    'strMsg = "The Number of " & fldval & " is missing. Please enter a value." & Chr(10)
    response = MsgBox(strMsg, vbYesNo)
    If response = vbYes Then
    'Me![Production Sheet Sub 1].Form![Cycles].SetFocus
    'DoCmd.GoToControl ("[Cycles]")
    End If

    End If


    End Sub

    and if you want to use a var (fldval or whatever) elsewhere in this module, dim it at the top of the module (outside any sub/function). anything dimmed in a sub/function goes out of scope when the sub/function terminates

    izy
    Last edited by izyrider; 03-27-03 at 03:06.

  7. #7
    Join Date
    May 2002
    Posts
    395
    That makes lots of sense.
    Thanks guys!!

Posting Permissions

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