Results 1 to 10 of 10
  1. #1
    Join Date
    Oct 2002
    Location
    Montreal Quebec
    Posts
    13

    Unhappy Unanswered: Store data in string

    I have a form that when you click on the cmd button it will transfer the value of the text box to the other form.

    This is the code I used....

    Forms![PCV_Dispatch_form]![txtCodeSupervisor].Value = Me![txtCodeSupervisor].Value

    When I look at the PCV_Dispatch_form I see that the value was transfered, but then what I would like to do is store the value in txtCodeSupervisor.

    So I add the following in the PCV_Dispatch_form..
    ***************

    Private Sub Form_Open(Cancel As Integer)

    Public strCodeSupervisor As Integer
    strCodeSupervisor = Me![txtCodeSupervisor].Value

    end sub

    But I keep on getting error that it can't contain a Null Value...Why is it that my value is not storing in my strCodeSupervior..

    Can anyone please help..

    Thanks in advance

  2. #2
    Join Date
    Sep 2002
    Location
    South Wales
    Posts
    580

    Transferring the value...

    Please clarify what you are trying to acheive...

    When the second form is open, do you want;

    a: an unbound field displaying the value from the previous form

    in which case just add an unbound text box with the code
    =Forms!OriginalFormNameHere!OriginalFieldNameHere

    b: The same field as used in the original form
    base the recordsource of form 2 on a query incorporating the original field

    c:Advise

    Please post a little more detail on what and why you are trying to do
    Last edited by garethdart; 10-16-02 at 08:53.

  3. #3
    Join Date
    Oct 2002
    Location
    Montreal Quebec
    Posts
    13
    What I would like to do is that
    my first form is named Ecran_PCP_form I have a textbo named txtCodeSupervisor that will display a number 0, 1 or 2. The when the user click on the Menu_Click button a second form opens.

    The name of the second form is PCV_Dispatch_form, this form also hasa textbox named txtCodeSupervisor that passes the value fron the first form to the second.

    I can see the value in the second form but then in my second form I have the following code that needs to execute.

    Private Sub Form_Load()

    'Specifies codes to agents

    'Verifies the computer name and gives access.
    intCodeSupervisor = Me!txtCodeSupervisor

    If (intCodeSupervisor = "0" Or "2") Then

    MsgBox ("Agent and at employee entrance")

    Me![DataID].Visible = False
    Me![Agent].Visible = False
    Me![Btn_HrsFinCall].Visible = False
    Me![Btn_Pause_View].Visible = False
    Me![Btn_Pause].Visible = False


    Else
    'NOTHING
    End If

    End Sub

    But I keep on getting a NULL value....I think the form opens before it an see the value, but I have no idea how to fix this...

    I also have the following code in the first form named Ecran_PCP_form
    **********************************
    Private Sub Btn_MainMenu1_Click()
    Forms![PCV_Dispatch_form]!txtCodeSupervisor = Me!txtCodeSupervisor
    intCodeSupervisor = Me!txtCodeSupervisor

    End Sub
    ***********************************

  4. #4
    Join Date
    Oct 2001
    Location
    Chicago
    Posts
    440
    Change form Load to Open

    **Edited**
    sorry - the above will still have null value

    If the form is only opened from the other form you could add this to the load event

    Me![txtCodeSupervisor] = Forms![Ecran_PCP_form ]!txtCodeSupervisor
    Last edited by Rockey; 10-16-02 at 12:37.

  5. #5
    Join Date
    Oct 2002
    Location
    Montreal Quebec
    Posts
    13
    I tried that but it didn't work...I also tried Form_current

  6. #6
    Join Date
    Oct 2002
    Location
    Montreal Quebec
    Posts
    13
    It still doesn't work......

  7. #7
    Join Date
    Sep 2002
    Location
    South Wales
    Posts
    580

    Question Try this

    I have re-created both forms as follows;

    Form Ecran_PCP_form includes an UNBOUND text box called

    txtCodeSupervisor

    '(Where does the data come from txtCodeSupervisor on your form Ecran_PCP_form?

    Form PCV_Dispatch_Form also includes a text box ALSO called

    txtCodeSupervisor which has the control source set to

    =[Forms]![Ecran_PCP_form]![txtCodeSupervisor]

    Form Ecran_PCP_form includes an command button to open PCV_Dispatch_Form


    PCV_Dispatch_Form includes the following in the load event...

    Private Sub Form_Load()

    'Specifies codes to agents

    'Verifies the computer name and gives access.

    Dim IntCodeSupervisor As String
    '****This was not declared in your code - Is it a local variable used only for the purpose
    '****of comparison? If so it is unneccessary - You can either query the field on the first form
    '****using code similer to this> If Not (Forms!ecran_pcp_form!txtCodeSupervisor = "1") Then

    IntCodeSupervisor = Forms!ecran_pcp_form!txtCodeSupervisor

    If Not (IntCodeSupervisor = "1") Then
    'Not sure how many circumstances you want to check for here - if there are likely to be more than
    '2 / 3 circumstances, maybee investigate CASE STATEMENTS here rather than an if statement...

    MsgBox ("Agent and at employee entrance")

    'Me![DataID].Visible = False
    'Me![Agent].Visible = False
    'Me![Btn_HrsFinCall].Visible = False
    'Me![Btn_Pause_View].Visible = False
    'Me![Btn_Pause].Visible = False

    Else

    'NOTHING

    End If

    End Sub



    '##############################################'## ###########################
    'This seems to replicate what I THINK you are trying to do i.e. They get 'the message if the code is 0 or 2
    'but not if it is 1 - Hope this helps

    Gareth Dart

  8. #8
    Join Date
    Oct 2001
    Location
    Chicago
    Posts
    440

  9. #9
    Join Date
    Aug 2002
    Location
    Québec, Canada
    Posts
    109
    You could pass an argument to the form you open like that:

    Code:
    DoCmd.OpenForm "FormName", acNormal, , , , , "22"
    Here, we pass the argument 22 (it can be a textbox value)

    Then, on the Form_load procedure of the openend form, access the Arguments like that:

    Code:
    me.txtTextBox = Me.OpenArgs
    JefB

  10. #10
    Join Date
    Oct 2002
    Location
    Montreal Quebec
    Posts
    13
    Thank You guys for your help

Posting Permissions

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