Results 1 to 6 of 6
  1. #1
    Lounger
    Join Date
    Jan 2006
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Reading profilestring (word 9.0 sp3)

    Hi,

    I've been looking for a solution around these boards (and elsewhere) but haven't found it so far, so if anyone could help me i would be VERY grateful. I've made a few templates with userforms. On the userform is a button which reads 'my data...' When the user clicks this, a new form opens into which the user can enter his mobile number e-mail etc. These will automatically appear in any document that the user makes. The data is stored in the user registry, using the profilestring property. So far everything is OK.

    My question is: When the user enters data for the first time the form is empty. This makes sense since the registry key doesn't exist yet. When the user wants to CHANGE his data, the form is still empty because it doesn't read the registry key. When i enter code to read the registry key it will do so, but will crash when the registry key doesn't exist. (when the user wants to enter data for the first time)

    Is there a way to check whether this registry key exists? (if exists... doen't work)

    I would very much appreciate any help to solve this unimportant but irritating problem.

    Paul

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Reading profilestring (word 9.0 sp3)

    What code are you using to read the registry? The System.PrivateProfileString method built into Word VBA will simply return an empty string if the provided key or value doesn't exist, so if you use that, there shouldn't be a problem.

  3. #3
    Lounger
    Join Date
    Jan 2006
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Reading profilestring (word 9.0 sp3)

    Hans,
    Thanks for your time and effort. Your remark about errors put me on the right track. and so I've finally solved my problem. <img src=/S/bananas.gif border=0 alt=bananas width=33 height=35>
    on initialize, if registry key doesn't exist, spaces are put in registry
    if registry key DOES exist, data from form is put into registry
    When you click OK data from form is put in registry

    This is the code i use:
    Private Sub CmdCancel_Click()
    Unload Me
    End Sub

    Private Sub CmkOK_Click()
    System.ProfileString("Persoonsgegevens", "Naam") = Me.TxtNaam
    System.ProfileString("Persoonsgegevens", "emailadres") = Me.TxtEmail
    System.ProfileString("Persoonsgegevens", "Mobielnummer") = Me.TxtMobiel
    System.ProfileString("Persoonsgegevens", "telefoonnummer") = Me.TxtTelDirect

    Unload Me

    End Sub

    Private Sub UserForm_Initialize()
    On Error GoTo Fout


    Fout:
    Select Case Err.Number
    Case 5843
    System.ProfileString("Persoonsgegevens", "Naam") = " "
    System.ProfileString("Persoonsgegevens", "emailadres") = " "
    System.ProfileString("Persoonsgegevens", "Mobielnummer") = " "
    System.ProfileString("Persoonsgegevens", "telefoonnummer") = " "
    Case Else
    Me.TxtNaam = System.ProfileString("Persoonsgegevens", "Naam")
    Me.TxtEmail = System.ProfileString("Persoonsgegevens", "emailadres")
    Me.TxtMobiel = System.ProfileString("Persoonsgegevens", "Mobielnummer")
    Me.TxtTelDirect = System.ProfileString("Persoonsgegevens", "telefoonnummer")
    End Select
    End Sub

  4. #4
    Lounger
    Join Date
    Jan 2006
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Reading profilestring (word 9.0 sp3)

    Hans,

    One last question: I've put the form into a startup template and want to be able to show it from a userform in another template. How do i do this? I tried to call it, but got the 'object required' failure.

    Thanks in advance,

    Paul

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Reading profilestring (word 9.0 sp3)

    Put a macro in a standard module in the startup template that opens the userform, e.g.

    Public Sub ShowForm()
    frmTest.Show
    End Sub

    You can call this macro from another template:

    Application.Run "ShowForm"

    If you set a reference to the startup template (in Tools | References...; this requires the template to have a unique project name, say MyTemplate), you can call it directly:

    MyTemplate.ShowForm

  6. #6
    Lounger
    Join Date
    Jan 2006
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Reading profilestring (word 9.0 sp3)

    Hans,

    Thanks very, very, very much

    Paul

Posting Permissions

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