open another form and imort string into it (1 Viewer)

cliff7376

Registered User.
Local time
Today, 05:30
Joined
Oct 10, 2001
Messages
107
I know this is probably a really easy thing to do. Basically I have a program that I am editing that makes a user enter in a sales number in one form to put it on a shiplist. Then they have to go into another form and enter the same sales order number to ship it. What I want to do is have the user open up the second form put the sales number in and in the before update event I want to put code in where it open's the other form takes the sales order number that i have saved in a string and enter it into the other form let it do it's thing and then close the form again. is this possible?
 

David Mack

Registered User.
Local time
Today, 05:30
Joined
Jan 4, 2000
Messages
53
Use the openargs option in the event you want to trigger the opening of the new form in:

dim stDocName as string
dim txtOrderNumber as string

stDocName = "frmYourSecondFormName"
txtOrderNumber = Me.txtNameOfYourOrderField

DoCmd.OpenForm stDocName, acNormal, , , acFormAdd, , txtOrderNumber

''''''''''''''''
txtOrderNumber is the OpenArgs variable passed into your second form.

Now in the OnOpen event of the second form set the text box value of the order form like this:

Me.txtWhateverYouCalltheNewField.value = me.OpenArgs

Should work fine.

Cheers,

Dave
 
J

Jerry Stoner

Guest
On your command button:

Dim SalesOrderNumber As String
SalesOrderNumber = YourFieldHere.Value
DoCmd.OpenForm "frmComp", _
DataMode:=acFormAdd, _
WindowMode:=acDialog, _
OpenArgs:=SalesOrderNumber

In the Load event for your form to open:

If Len(Me.OpenArgs) > 0 Then
Me.SalesOrderNumberField = Me.OpenArgs
End If
DoCmd.Maximize
ExitHere:
Exit Sub

Should get you close though I didnt test it. There may be an easier way but ...
Jerry
 

cliff7376

Registered User.
Local time
Today, 05:30
Joined
Oct 10, 2001
Messages
107
thank you very much for your help. I have one more problem though. I am putting the openform code in the before update part of my form. I need to have a do while loop in my main form waiting for a bool vaue or something to be returned from the form i opened to tell the program that it is finished doing what i asked it to do and can go on and do the next step on the main form. How would one go about this?

[This message has been edited by cliff7376 (edited 05-14-2002).]
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 00:30
Joined
Feb 19, 2002
Messages
43,603
If the second form is based on a table that is related to that entered on the first form, the record on the first form MUST be saved prior to opening the second form. That being the case, move the OpenForm method to the AfterUpdate event of the first form.

If you also use these forms to display existing records, you should not open the second form in add mode but open it in edit mode instead. In this case, use the "where" parameter of the OpenForm method to pass the related key field.
 

Users who are viewing this thread

Top Bottom