Message Box Cycle

Uvuriel03

Registered User.
Local time
Today, 09:22
Joined
Mar 19, 2008
Messages
115
I'm building a form to enter new receipts. In order to normalize all the data, each line in the Inbound table is linked to a separate line in the Trucks table by a truck number.

When I open the receipts form, I want a message box to pop up asking if this will be a new truck number. If the user clicks yes, a separate form pops up requesting the information for that truck. If not, it just opens up the receipts form.

The way I have it set up right now isn't working. I tried setting up a textbox to pop up on load, which worked fine, but then if the user clicked Yes, the Receipts form would end up on top of the Trucks form. I tried sticking a "Select object" in there, but that didn't work. Maybe I didn't have it in the right place.

Either way, this is what I have right now. The code below is in the first field the cursor goes to. Unfortunately, it isn't working as I'd like. The same thing is happening as described above--the Trucks form doesn't get focus. I think, hypothetically, if the trucks form could get focus, it'd solve the problem because on closing the trucks form, it sets the trucks field in the Receipts form to whatever it is in the related field on the Trucks form.

Code:
    If IsNull([TRUCK]) Then
    If (MsgBox("Will this be a new truck number?", 1) = 1) Then
        DoCmd.OpenForm "TRUCKS", acNormal, "", "", , acNormal
        DoCmd.SelectObject acForm, "TRUCKS", no
        DoCmd.GoToControl "I/O"
    Else
    DoCmd.GoToControl "ID"
    End If
    End If

Any ideas?

Thanks!
 
a couple of thoughts from me:

1) doesn't the docmd.openform code automatically select the opened form as the active object?
2) and if that is true, there would not be a control that is set to receive focus, just the form.
3) do you have all of the control names and syntaxes right in your code lines?
4) can you really use a number instead of "vb" code (such as "vbyesno") within the msgbox() code instead of the integers like "1"? I never have, that's why i mention.
 
Not sure if this will completely solve your problems, but you can check out the "InputBox" method. It is called from the current form.

You can assign the input to this into a variable and use that to either work some logic or assign to textboxes, etc.

E.g., sVariable = InputBox("What is your name?", .... )

-dK
 
Marley,

1) doesn't the docmd.openform code automatically select the opened form as the active object?
2) and if that is true, there would not be a control that is set to receive focus, just the form.
3) do you have all of the control names and syntaxes right in your code lines?
4) can you really use a number instead of "vb" code (such as "vbyesno") within the msgbox() code instead of the integers like "1"? I never have, that's why i mention.

1. I thought that would be the case, but it's entirely possible that some other action in my form brings the Receipt box into focus after the Trucks box is brought into focus. I'm trying to track that down... My forms are pretty loaded with code.
2. Yeah, I wondered about that, but I figured better safe than sorry
3. Yep, I do.
4. Actually if you look it up in the MS Help file, that's how they have it set up. I just copied and edited that because I couldn't remember how to do it myself offhand.

MsgBox("Confirm changes?",1)=1 You click OK in a dialog box in which the MsgBox function displays Confirm changes?. If you click Cancel in the dialog box, Access ignores the action.




dkinley said:
Not sure if this will completely solve your problems, but you can check out the "InputBox" method. It is called from the current form.

You can assign the input to this into a variable and use that to either work some logic or assign to textboxes, etc.

E.g., sVariable = InputBox("What is your name?", .... )

-dK

Dkinley,

Thanks, but that's not quite what I'm looking for. I need it to ask first, and then have the form pop up. This is for data entry reasons--I've got the form set to limit the amount and type of data entered so as to avoid data entry errors.
 
Update: I've got a setvalue command in the OnCurrent event. I know that affects the timing of what I can use, when.
 
Yay! Victory!

Just fyi! I figured out how to make it work. ^_^

Due to the code I have on the OnCurrent event, anything I put on an event that fired before that would be done before the update on the OnCurrent. IE, when I tried to get the Trucks form to be selected, it WAS--and then a field labled "Key" in the Receipts form was updated on the OnCurrent event, bringing THAT form back into focus.

MUAHAHA!!

So! What I did was this:

On the BeforeUpdate event, I have the Trucks form open. Then, on the Truck form's OnLoad event (aka before the "Key" field on the Receipts form is updated), a popup box comes up asking if the user needs to enter a new truck or not. If they click yes, it autoupdates the truck number and is then ready for the rest of the info to be entered. If they click no, it closes the Trucks box and automatically goes back to the receipt form.

Now! There's one more thing that actually makes this WORK, since the OnCurrent event still fires after the truck number is updated in the Trucks form. The first field that gets focus after the OnCurrent event is the "ID" field. On the GetFocus event of the "ID" field, I have this code to check if the Trucks form is open:

Code:
    If CurrentProject.AllForms("TRUCKS").IsLoaded Then
    DoCmd.SelectObject acForm, "TRUCKS", NO
    End If
So it checks if the Trucks form is loaded. If it is (which it will be if the user selected Yes upon the popup), it brings that form into focus. If it isn't open (aka the user selected no), then nothing happens and it just stays on the Receipt page.

Yay! VICTORY!!
 

Users who are viewing this thread

Back
Top Bottom