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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unloading two forms at once

Status
Not open for further replies.

jabarden

Technical User
Jun 16, 2003
19
US
I have a program for creating workorders. After the user finishes the order, they click the submit button, which loads another form, which has two command buttons, Yes and No, asking if they want to fill out another workorder,

If they click yes, I need it to hide the Yes/No form, input the information into the database, and clear out the information that the user filled in.

If they click no, I need it to input the information into the database and to unload both of the forms.

Thanks alot
JABSNH
 
once the user types in the data, it's in there. you don't have to 'input the data into the database'.

what code do you already have behind your YES and NO buttons?

i'd suggest that if they hit YES, you put

DoCmd.Close acForm, "DataEntryFormName", acSaveNo
docmd.openform "DataEntryFormName", , , , acFormAdd
DoCmd.Close acForm, "ThisFormName", acSaveNo

if they hit NO, put just the first and third lines of code

substitute your two form names of course.

another option is instead of using a separate form to ask if they want to add another record, use a messagebox to ask the question:

in the SUBMIT buttons' OnClick event, put

Code:
Dim bolContinue As Boolean
    bolContinue = MsgBox("Would you like to continue?", vbYesNo, "Continue")
    If bolContinue = vbYes Then
        blah
    Else
        blah2
    End If
 
Hey: thanks for writing back

The MSG box was the type thing that I was wanting to do.
What I figured I would do would be when they click YES to fill out another workorder to have it unload the form, and just load it again, but that didn't work, it only closes the form. The NO button works fine. The code that I have under the submit button is below:

Private Sub CmdSubmit_Click()
Dim bolContinue As Boolean
bolContinue = MsgBox("Do you have another work order?", vbYesNo, "Another Workorder?")
If bolContinue = vbYes Then
DoCmd.Close acForm, "FrmWorkorder", acSaveNo
DoCmd.OpenForm acForm, "FrmWorkorder", , , , acFormAdd
Else
DoCmd.Close acForm, "FrmWorkorder", acSaveNo
End If
End Sub

Thanks Alot
JABSNH
 
improper syntax?

DoCmd.OpenForm "FrmWorkorder", , , , acFormAdd

not

DoCmd.OpenForm acForm, "FrmWorkorder", , , , acFormAdd

??
 
Private Sub CmdSubmit_Click()
Dim bolContinue As Boolean
bolContinue = MsgBox("Do you have another work order?", vbYesNo, "Another Workorder?")
If bolContinue = vbYes Then
DoCmd.Close acForm, "FrmWorkorder", acSaveNo
DoCmd.OpenForm "FrmWorkorder", , , , acFormAdd
Else
DoCmd.Close acForm, "FrmWorkorder", acSaveNo
End If
End Sub


It did the same thing with this code; The form closed, but didn't reopen. Could it be that since the submit button is on the form, when I tell the form to close, it closes before it has a chance to execute the code telling it to reopen?

Thanks Alot,
JABSNH
 
Just so's you know, the acSaveNo applies to changes in the form design, not to data in the form.

If you want to roll back changes to the form, put "me.undo" in your code, on the line before you close the form.

Of course, if your user has already moved to a different record, clicked the record selector (the vertical bar to the left of the record), or used the appropriate menu item or shortcut key, the record will already have been saved.

If you really want to do this properly, and safely, you'll want to either use an unbound form or an unbound recordset. I've never used the latter, so I can't advise you on it. Using an unbound form is a bit more work than a form that's bound to a table or query, but it's not so bad. You'll want to read some help files, but the basic approach is to make a recordset and fill the controls on your form from that recordset (in code). Then, when the user makes a choice of whether to save or not, you can either update the appropriate table(s) or just close the form, abandoning the new data.

Hope this helps.

Jeremy

==
Jeremy Wallace
AlphaBet City Dataworks
Affordable Development, Professionally Done

Please post in the appropriate forum with a descriptive subject; code and SQL, if referenced; and expected results. See thread181-473997 for more pointers.
 
I'm going to block all of the controls so the user can't access the data at all.

Ideally, I would like the user to input their data, when they finish, click the submit button, which will print a report to a network printer located in maintenance, and then bring up the message box, asking if they want to fill out another workorder. If yes moving to the next record, (the user doesn't know this). If no, closes the application.

Thanks for any advice.
JABSNH
 
forget the acsaveno, just take it out it doesnt matter.

as for the rest of the code, i am using the exact same thing in one of my db's. i'll check again at work tomorrow.
 
there's something wierd going on.
with exact same code as yours typed in, mine works fine. but when i copy your code and paste it in, it doesnt work as you say it doesnt. i've tried pasting one line at a time to see what the problem is, but cant find it. perhaps there is some hidden character or something (maybe if you pasted it from this web page it got honked up or something).

i suggest clearing out the whole sub, and typing it in from scratch. no pasting. see how that works.

by the way, i had acSaveNo in my thing because if users filter or sort on a form, Access will ask when they close the form if they want to save changes (the filter or the OrderBy) so that's why i put it in there. you can use it or not. i think it's there cause i usually put it in whether or not i think people might filter or sort or not.

g
 
I typed it in and it still did the same thing. Is there a way to use visual basics code (Load and Unload) to do it?

Thanks for all the help
JABSNH
 
GingerR:

Can I E-mail the Database to you, and you see if you can see something wrong with it?


Thanks
JABSNH
 
sure. compact first, zip (if over 1 MB) and mail to rowe147@hotmail.com
 
Just thought you might want to know....I was playing around with the code, and I think that what it is, is that the If statement is always false, because I changed the code to the code listed below. What it did whether I clicked yes or no, It would close and then open the form

if BolContinue = VbNo then
DoCmd.Close AcForm, "FrmWorkorder"
Else
DoCmd.Close AcForm, "FrmWorkorder"
DoCmd.Openform "FrmWorkorder"
Endif

JABSNH
 
bolContinue should be intContinue or lngContinue - vbYes and vbNo don't necessarily correspond to the boolean values True and False. So when you're assigning the value to bolContinue, it attempts to convert the integer (in this case the number represented by vbYes) to boolean, and you ASSUME it converts to True. Which it doesn't.

Code:
'true if "Yes" is selected, otherwise false
bolContinue = (msgbox("Question?",vbYesNo) = vbYes)


Or do it as an int/long, like so:
Code:
'Can be either vbYes or vbNo or vbOK or vbCancel or whatever
intContinue = (msgbox("Question?",vbYesNo))
If intContinue = vbYes then
else if intContinue = vbNo then
    'etc
else 
    'etc
End If


--
Find common answers using Google Groups:
[URL unfurl="true"]http://groups.google.com/groups?group=comp.databases.ms-access[/URL]

Corrupt MDBs FAQ
[URL unfurl="true"]http://www.granite.ab.ca/access/corruptmdbs.htm[/URL]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top