Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

retrieve user inputted data from form

Status
Not open for further replies.

ldickie

Technical User
Jul 17, 2006
3
US
Hi all

I need to take some user inputted variables and generate some new data from them. I've tried a few different ways to go about this, and I'm not really sure which is the best way to go about it (I haven't been able to get either to work).

I have a module that generates all the information I need that works fine, but I'm not sure how to get the inputted data to it.

I have a form that launched my MakeCodes module on the click event of a button, and then in that code I call a sub to get the user variables. This is where I'm confused, as I found this code through some searching and am not really sure how it works.

Code:
Private Sub GetUserVariables()
    Debug.Print "In GetUserVariables Sub"
    DoCmd.OpenForm "frmInputSampleCodingVariables", acNormal
    
    While SysCmd(acSysCmdGetObjectState, acForm, "frmInputSampleCodingVariables") = acObjStateOpen
        DoEvents 'Do Nothing Wait for Closing
        stBHID = Forms!frmInputSampleCodingVariables!BHID
        intSampleStart = Forms!frmInputSampleCodingVariables!SampleStart
        intSampleEnd = Forms!frmInputSampleCodingVariables!SampleEnd
        stOreZone = Forms!frmInputSampleCodingVariables!OreZone
        stSTD1 = Forms!frmInputSampleCodingVariables!STD1
        stSTD2 = Forms!frmInputSampleCodingVariables!STD2
        stSTD3 = Forms!frmInputSampleCodingVariables!STD3
        stSTD4 = Forms!frmInputSampleCodingVariables!STD4
        stSTD5 = Forms!frmInputSampleCodingVariables!STD5
    Wend
End Sub

When I run this it opens the form for input, and (is supposed to?) wait until the form is closed to continue. When I fill in the form and close it I get an error that it can't find the form. When stepping through the loop the variables change to what I put in the form, so I'm guessing that when I close the form it is in the middle of the loop and tries to assign the variable to the control from the form, which is closed and is causing the error (the immediate window only displays "In GetUserVariables Sub"). How do I get around this?

I'm sure this isn't the best way to accomplish this task though. I was trying to do something where the submit/close event of the form would get the data and call the Sub to make my new data, but I couldn't get that working at all.

Thanks for the help

Lucas
 
How are ya ldickie . . .

Change your routine to:
Code:
[blue]Public Sub GetUserVariables()
   Dim frmName As String
   
   frmName = "frmInputSampleCodingVariables"
   DoCmd.OpenForm frmName, acNormal, , , , [purple][b]acDialog[/b][/purple][/blue]
Then in the [blue]UnLoad[/blue] event of [blue]frmInputSampleCodingVariables[/blue]:
Code:
[blue]   stBHID = Me!BHID
   intSampleStart = Me!SampleStart
   intSampleEnd = Me!SampleEnd
   stOreZone = Me!OreZone
   stSTD1 = Me!STD1
   stSTD2 = Me!STD2
   stSTD3 = Me!STD3
   stSTD4 = Me!STD4
   stSTD5 = Me!STD5[/blue]
[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .
 
Worked great!

I just had to change those variables to public and it worked fine.

Thanks for the help
 
If I change the view to acFormDS, it doesn't pause the code waiting until the form is closed. How do you get around that?
 
ldickie . . .

I've never had to use the action [blue]acFormDS[/blue]. What ever you do set the forms [blue]Modal[/blue] property to [blue]Yes[/blue] . . .

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top