Results 1 to 10 of 10
  1. #1
    Join Date
    Dec 2002
    Location
    Phoenix, AZ
    Posts
    122

    Cool Unanswered: Public Variables

    Is it possible to set a public variable from a form? I would like to give the user the ability to set variables through a form. How can I do this??? Any ideas would be great!

  2. #2
    Join Date
    Jan 2003
    Posts
    46
    You will need to declare the public variable in a module:

    Public pStr as string

    Then use some event of the form or its controls to pass a value to the public variable. For instance:


    Private Sub cboYourCombo_AfterUpdate()
    pStr = Me.cboYourCombo.column(1)
    End sub


    Cheers,
    zambezibill

  3. #3
    Join Date
    Feb 2003
    Location
    Auckland, NZ
    Posts
    150

    Re: Public Variables

    Yes it is

    Create a module and in the module type the following. Note this should not be within a sub or a function

    Global MyVariable as String


    You will be able to reference MyVariable from any form within the database.

    Private Sub Form_Open()
    MyVariable = "TEST"
    End Sub

  4. #4
    Join Date
    Dec 2002
    Location
    Phoenix, AZ
    Posts
    122
    Hey zambezibill,

    I did what you posted (kind'a) and it worked!!! Thanks. But now I have another problem. I can set a variable everytime I go to the form but when I close the database and open it again the VARIABLE resets to nothing. Can I set a variable and have it stay set to whatever I choose for how long I choose- even when I close the database?

  5. #5
    Join Date
    Feb 2003
    Location
    Auckland, NZ
    Posts
    150
    Why not store it in a table and just change it when needed

  6. #6
    Join Date
    Oct 2002
    Location
    Leicester - UK
    Posts
    820
    it's that or put it in a file eg
    the bold bit are the one that are inportant

    Option Compare Database
    Option Explicit
    Dim i As Integer
    Dim inboxfolder As MAPIFolder

    Sub getMail()
    Dim inboxcontense As Outlook.Items, email As MailItem
    Dim rs As DAO.Recordset
    Dim temp As String, temp1 As String


    Open "H:/mdbfiles/helpdesk.dat" For Input As #1
    Input #1, temp, temp1
    Close #1




    Set inboxfolder = CreateObject("Outlook.Application").GetNamespace(" MAPI").GetFolderFromID(temp, temp1)
    Set inboxcontense = inboxfolder.Items
    Set rs = CurrentDb.OpenRecordset("jobs", , dbAppendOnly)
    For Each email In inboxcontense
    If email.UnRead Then
    With rs
    .AddNew
    !User = email.SenderName
    !DateReported = email.SentOn
    !DescriptionBrief = email.Subject
    !DescriptionFull = email.Body
    !Status = 1
    .update
    End With
    End If
    email.UnRead = False
    Next
    rs.Close
    End Sub

    Sub makefile()
    Set inboxfolder = CreateObject("Outlook.Application").GetNamespace(" MAPI").PickFolder
    Open "H:/mdbfiles/helpdesk.dat" For Output As #1
    Write #1, inboxfolder.EntryID, inboxfolder.StoreID
    Close #1
    End Sub
    Definition of a Beginner, Someone who doesn't know the rules.

    Definition of an Expert, Someone who knows when to ignore the rules.

  7. #7
    Join Date
    Dec 2002
    Location
    Phoenix, AZ
    Posts
    122
    THANKS FOR YOUR REPLIES.

    M.Timoney: Thanks, I going to try this-I'll let you know how this works out.

    Machado : How would you call the variable from a table?

  8. #8
    Join Date
    Feb 2003
    Location
    Auckland, NZ
    Posts
    150
    Create a table say called tblVariables

    Create two fields.

    VariableName
    VariableValue

    add the variables to the variable field

    When you want to change the value of a variable you use an update query

    UPDATE tblVariables
    SET VariableValue = '" & Value & "'
    WHERE VariableName = '" & NameOFVariable & "'

    to Read the variable just use the SELECT statement

  9. #9
    Join Date
    Oct 2002
    Location
    Leicester - UK
    Posts
    820
    the simple fact of the matter is that you have to right the variable to the hard drive if you want to keep it which means file or data table and it don't don't make the damnest bit of difference apart from the fact that teh table is larger that the file and the table is slightly safer (you aren't going to accidently right over any key files mind you, if you do manage to do that you really shouldn't be using file io at all)
    Definition of a Beginner, Someone who doesn't know the rules.

    Definition of an Expert, Someone who knows when to ignore the rules.

  10. #10
    Join Date
    Dec 2002
    Location
    Phoenix, AZ
    Posts
    122

    Thanks!

    Thanks for all 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
  •