MsgBox prompt

ScrmingWhisprs

I <3 Coffee Milk.
Local time
Today, 15:43
Joined
Jun 29, 2006
Messages
156
Yet another issue with my volunteer tracker...

On my Workers form, frmWorkers, I have a subform that displays each night they worked with TimeIn and TimeOut, and DateID, which links that transaction to tblDates. I also have a Sign In button on my form that opens a popup form based on tblBuildingTransactions, and most of the information including their name and DateID is filled in. That works great. However, I would like a MsgBox to appear if the DateID on that form matches a DateID that is on the Workers subform. This will mean they are already signed in for that particular night. I have the following code, but it says it "cannot find the field 'frmWorkersSubBuild' referred to in you expression."

Code:
Private Sub Form_Load()

If Me.BuildingDate = Forms!frmWorkers!frmWorkersSubBuild.Form!BuildingDate Then
MsgBox "This worker is already signed in.", vbExclamation, "Error"
End If

End Sub

Maybe I'm not just referring to the form correctly. The form is open, the Sign-In form that this code is attached to is a pop up.

Eventually I would like Access to ignore adding this new transaction when the OK button on the message box is click, but I'd like to get the message box to work first.

Thanks
ScrmingWhisprs
 
Make sure frmWorkersSubBuild is the name of the CONTROL that houses the subform on the main form. You need to reference the subform control, which may, or may not, be named the same as your subform. If it is named something else your code won't work unless you change your code to refer to its actual name.
 
Thanks!

I found my error. Really stupid actually. Works great now.

ScrmingWhisprs
 
Well, the whole thing worked fine until we started using this last night, and there was a conflict with some other code that I had in the same Form Load event. This is the code I have:
Code:
If Me.DateID = Forms!frmWorkers!frmWorkerSubBuild.Form!DateID Then
MsgBox "This worker is already signed in.", vbExclamation, "Error"
End If
The message box displays fine, but after clicking OK, it still adds a record. So now I need to add something to cancel creating a new transaction and closing the popup form when the OK button is clicked on the message box.

Thanks!
ScrmingWhisprs
 
Basically when the popup form is opened, a new transaction is automatically created because some information is already filled information from background forms. So what's happening is, the message box appears because there are 2 identical DateID numbers, but there is no code to get rid of the record that was just created.
 
I'm not sure, based on your description, where you need to trap things and cancel and undo them. It might be beneficial to actually see your database.
 
You said the magic word! UNDO!

I placed the text in red into my code and now it works great.

Code:
If Me.DateID = Forms!frmWorkers!frmWorkerSubBuild.Form!DateID Then
MsgBox "This worker is already signed in.", vbExclamation, "Error"
[COLOR="Red"]Me.Undo
DoCmd.Close acform, Me.Name[/COLOR]
End If

Before I was trying delete commands, cancel event commands, etc.

KISS

Thanks
ScrmingWhisprs
 
Ok, I'm not really sure what happened, but for some reason this code just stopped working! I don't get any error message, and the message box doesn't appear!

Help!
ScrmingWhisprs
 
Ok, I'm not really sure what happened, but for some reason this code just stopped working! I don't get any error message, and the message box doesn't appear!

Help!
ScrmingWhisprs

Go into the code and set a breakpoint so that it will pause and you can F8 through to see if it is hitting the code you need. You might need to import everything into a new mdb file as something might have corrupted.
 
I'm not exactly sure what you mean by breakpoint... is that just a space?
 
In the VB editor click in the left margin beside the line want to break point. A brown dot should appear and a line will be highlighted in brown. When the running code reaches that point it will halt and you can advance one line at a time by pressing F8. You can check the values of identifiers by holding the cursor over them. To start the code running normally again use F5.
 
OK, so I did that, and when the form loaded, the VB editor opened with a yellow arrow on the first line.

When I hit F8, the arrow jumped down to End If. I'm not really sure what I'm looking for going through one line at a time.

SW
 
Then it looks like the if condition returned a false so it skipped everything. Did you have an Else field.
Can you post your code so we can see it.
 
An interesting find.........

The code ONLY works if there is one record in that worker's subform OR if I've selected the first date they've worked and try to sign them in on that date.

So if they've worked 3 nights, and I try to sign them in again on the third night, the form will load without the MsgBox appearing.

I'm not really sure how to get around this...

Here is my code:
Code:
If Me.DateID = Forms!frmWorkers!frmWorkerSubBuild.Form!DateID Then
MsgBox "This worker is already signed in.", vbExclamation, "Error"
Me.Undo
DoCmd.Close acform, Me.Name
End If

SW
 

Users who are viewing this thread

Back
Top Bottom