MsgBox window when you receive a new record in an IM type of DB

I

Iram

Hello.
I have created an Access database that will be shared by a few people that
will work almost as an Instant Messanger. The querey on the "Main" form pulls
all records created by the person logged in to the computer (using a module
that pulls the LAN login ID) and any record assigned to the person logged in.
The "Main" screen also refreshes automatically every 60 seconds.

I would like to add a feature and need your help. I need a pop up window to
appear indicating "A new task has been sent to you" and a beep sound occur
when a person recieves a new record from someone else. This feature is needed
since most folks have the access database minimized most of the time.

I was thinking of creating a "MsgBox" macro that would run on "After Update"
of the "Main" form however since the person logged in will create records to
the MsgBox will appear everytime.

I would rather have it created in VB that does something like....

After Update on form "Main", If new record's "Assigned To" equals me
fOsUserName()

(fyi, I am currently using the fOsUserName() module which pulls the LAN Login
ID and puts it into a different field called "Created By")

Then Run a MsgBox that says "A new task has been sent to you" with an "OK"
button and with a beep sound.


Is this possible?

Your help is greatly appreciated.

Iram/mcp
 
S

Stuart McCall

Iram said:
Hello.
I have created an Access database that will be shared by a few people that
will work almost as an Instant Messanger. The querey on the "Main" form
pulls
all records created by the person logged in to the computer (using a
module
that pulls the LAN login ID) and any record assigned to the person logged
in.
The "Main" screen also refreshes automatically every 60 seconds.

I would like to add a feature and need your help. I need a pop up window
to
appear indicating "A new task has been sent to you" and a beep sound occur
when a person recieves a new record from someone else. This feature is
needed
since most folks have the access database minimized most of the time.

I was thinking of creating a "MsgBox" macro that would run on "After
Update"
of the "Main" form however since the person logged in will create records
to
the MsgBox will appear everytime.

I would rather have it created in VB that does something like....

After Update on form "Main", If new record's "Assigned To" equals me
fOsUserName()

(fyi, I am currently using the fOsUserName() module which pulls the LAN
Login
ID and puts it into a different field called "Created By")

Then Run a MsgBox that says "A new task has been sent to you" with an "OK"
button and with a beep sound.


Is this possible?

Your help is greatly appreciated.

Iram/mcp

The way I normally handle this is to use the API. You can try it by grabbing
the code here:

http://www.smccall.demon.co.uk/MiscApi.htm#Netsend

The only caveat is that you need to know the user's machine name.
 
E

Eugene

Stuart,

I hope you can help me, I have added your code to my database. The code
appears to execute but does not sent a message to the users screen. Here is
the code....

****************************************************
Option Compare Database
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hHandle As Long) As Long

Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" _
(ByVal lpFileName As String, ByVal dwDesiredAccess As Long, _
ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, _
ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, _
ByVal hTemplateFile As Long) As Long

Private Declare Function WriteFile Lib "kernel32" _
(ByVal hFile As Long, ByVal lpBuffer As Any, ByVal nNumberOfBytesToWrite
As Long, _
lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Long) As Long

Private Const FILE_ATTRIBUTE_NORMAL = &H80
Private Const FILE_SHARE_READ = &H1
Private Const GENERIC_WRITE = &H40000000
Private Const OPEN_EXISTING = &H3
Public Function NetSendMsg(FromName As String, MachineName As String,
Message As String) As Boolean
Const NUL = vbNullChar
Dim buf As String
Dim bytesWritten As Long
Dim hFile As Long
Dim SlotName As String
'
buf = FromName & NUL & MachineName & NUL & Message & NUL & NUL
SlotName = "\\" & MachineName & "\mailslot\messngr"
'
hFile = CreateFile(SlotName, GENERIC_WRITE, FILE_SHARE_READ, 0&, _
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0&)
If hFile Then
NetSendMsg = CBool(WriteFile(hFile, buf, Len(buf), bytesWritten, 0&))
CloseHandle hFile
End If
End Function










Private Sub Add_New_Record_Click()
On Error GoTo Err_Add_New_Record_Click


DoCmd.GoToRecord , , acNewRec

DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

Exit_Add_New_Record_Click:
Exit Sub

Err_Add_New_Record_Click:
MsgBox Err.Description
Resume Exit_Add_New_Record_Click

End Sub
Private Sub Print_Record_Click()
On Error GoTo Err_Print_Record_Click


DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.PrintOut acSelection

Exit_Print_Record_Click:
Exit Sub

Err_Print_Record_Click:
MsgBox Err.Description
Resume Exit_Print_Record_Click

End Sub




Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.[Text31] = Time()

success = NetSendMsg("PRI Test Message", "D61PKFG1", "Please call me ASAP")


End Sub

Private Sub Print_Form_Click()
On Error GoTo Err_Print_Form_Click


DoCmd.PrintOut

Exit_Print_Form_Click:
Exit Sub

Err_Print_Form_Click:
MsgBox Err.Description
Resume Exit_Print_Form_Click

End Sub
Private Sub Close_Form_Click()
On Error GoTo Err_Close_Form_Click


DoCmd.Close

Exit_Close_Form_Click:
Exit Sub

Err_Close_Form_Click:
MsgBox Err.Description
Resume Exit_Close_Form_Click

End Sub



Private Sub Refresh_data_Click()
On Error GoTo Err_Refresh_data_Click


DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70



Exit_Refresh_data_Click:
Exit Sub

Err_Refresh_data_Click:
MsgBox Err.Description
Resume Exit_Refresh_data_Click

End Sub
Private Sub Click_Here_for_Current_PRI_Totals_Click()
On Error GoTo Err_Click_Here_for_Current_PRI_Totals_Click

Dim stDocName As String

stDocName = "CURRENT"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_Click_Here_for_Current_PRI_Totals_C:
Exit Sub

Err_Click_Here_for_Current_PRI_Totals_Click:
MsgBox Err.Description
Resume Exit_Click_Here_for_Current_PRI_Totals_C

End Sub
****************************************************

Any suggestions for a newbie?

Thanks,
Eugene
 
S

Stuart McCall

Eugene said:
Stuart,

I hope you can help me, I have added your code to my database. The code
appears to execute but does not sent a message to the users screen. Here
is
the code....

****************************************************
Option Compare Database
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hHandle As Long) As Long

Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" _
(ByVal lpFileName As String, ByVal dwDesiredAccess As Long, _
ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, _
ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long,
_
ByVal hTemplateFile As Long) As Long

Private Declare Function WriteFile Lib "kernel32" _
(ByVal hFile As Long, ByVal lpBuffer As Any, ByVal nNumberOfBytesToWrite
As Long, _
lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Long) As Long

Private Const FILE_ATTRIBUTE_NORMAL = &H80
Private Const FILE_SHARE_READ = &H1
Private Const GENERIC_WRITE = &H40000000
Private Const OPEN_EXISTING = &H3
Public Function NetSendMsg(FromName As String, MachineName As String,
Message As String) As Boolean
Const NUL = vbNullChar
Dim buf As String
Dim bytesWritten As Long
Dim hFile As Long
Dim SlotName As String
'
buf = FromName & NUL & MachineName & NUL & Message & NUL & NUL
SlotName = "\\" & MachineName & "\mailslot\messngr"
'
hFile = CreateFile(SlotName, GENERIC_WRITE, FILE_SHARE_READ, 0&, _
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0&)
If hFile Then
NetSendMsg = CBool(WriteFile(hFile, buf, Len(buf), bytesWritten,
0&))
CloseHandle hFile
End If
End Function










Private Sub Add_New_Record_Click()
On Error GoTo Err_Add_New_Record_Click


DoCmd.GoToRecord , , acNewRec

DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

Exit_Add_New_Record_Click:
Exit Sub

Err_Add_New_Record_Click:
MsgBox Err.Description
Resume Exit_Add_New_Record_Click

End Sub
Private Sub Print_Record_Click()
On Error GoTo Err_Print_Record_Click


DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.PrintOut acSelection

Exit_Print_Record_Click:
Exit Sub

Err_Print_Record_Click:
MsgBox Err.Description
Resume Exit_Print_Record_Click

End Sub




Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.[Text31] = Time()

success = NetSendMsg("PRI Test Message", "D61PKFG1", "Please call me
ASAP")


End Sub

Private Sub Print_Form_Click()
On Error GoTo Err_Print_Form_Click


DoCmd.PrintOut

Exit_Print_Form_Click:
Exit Sub

Err_Print_Form_Click:
MsgBox Err.Description
Resume Exit_Print_Form_Click

End Sub
Private Sub Close_Form_Click()
On Error GoTo Err_Close_Form_Click


DoCmd.Close

Exit_Close_Form_Click:
Exit Sub

Err_Close_Form_Click:
MsgBox Err.Description
Resume Exit_Close_Form_Click

End Sub



Private Sub Refresh_data_Click()
On Error GoTo Err_Refresh_data_Click


DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70



Exit_Refresh_data_Click:
Exit Sub

Err_Refresh_data_Click:
MsgBox Err.Description
Resume Exit_Refresh_data_Click

End Sub
Private Sub Click_Here_for_Current_PRI_Totals_Click()
On Error GoTo Err_Click_Here_for_Current_PRI_Totals_Click

Dim stDocName As String

stDocName = "CURRENT"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_Click_Here_for_Current_PRI_Totals_C:
Exit Sub

Err_Click_Here_for_Current_PRI_Totals_Click:
MsgBox Err.Description
Resume Exit_Click_Here_for_Current_PRI_Totals_C

End Sub
****************************************************

Any suggestions for a newbie?

Thanks,
Eugene

Stuart McCall said:
The way I normally handle this is to use the API. You can try it by
grabbing
the code here:

http://www.smccall.demon.co.uk/MiscApi.htm#Netsend

The only caveat is that you need to know the user's machine name.


Did you place my code in a standard module (ie not a form or report module),
because that's where it needs to live. Also, what windows version are you
using?
 
E

Eugene

I am running xp.

As a newbie, I am not sure what you mean by standard module or where it
would be.



Stuart McCall said:
Eugene said:
Stuart,

I hope you can help me, I have added your code to my database. The code
appears to execute but does not sent a message to the users screen. Here
is
the code....

****************************************************
Option Compare Database
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hHandle As Long) As Long

Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" _
(ByVal lpFileName As String, ByVal dwDesiredAccess As Long, _
ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, _
ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long,
_
ByVal hTemplateFile As Long) As Long

Private Declare Function WriteFile Lib "kernel32" _
(ByVal hFile As Long, ByVal lpBuffer As Any, ByVal nNumberOfBytesToWrite
As Long, _
lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Long) As Long

Private Const FILE_ATTRIBUTE_NORMAL = &H80
Private Const FILE_SHARE_READ = &H1
Private Const GENERIC_WRITE = &H40000000
Private Const OPEN_EXISTING = &H3
Public Function NetSendMsg(FromName As String, MachineName As String,
Message As String) As Boolean
Const NUL = vbNullChar
Dim buf As String
Dim bytesWritten As Long
Dim hFile As Long
Dim SlotName As String
'
buf = FromName & NUL & MachineName & NUL & Message & NUL & NUL
SlotName = "\\" & MachineName & "\mailslot\messngr"
'
hFile = CreateFile(SlotName, GENERIC_WRITE, FILE_SHARE_READ, 0&, _
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0&)
If hFile Then
NetSendMsg = CBool(WriteFile(hFile, buf, Len(buf), bytesWritten,
0&))
CloseHandle hFile
End If
End Function










Private Sub Add_New_Record_Click()
On Error GoTo Err_Add_New_Record_Click


DoCmd.GoToRecord , , acNewRec

DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

Exit_Add_New_Record_Click:
Exit Sub

Err_Add_New_Record_Click:
MsgBox Err.Description
Resume Exit_Add_New_Record_Click

End Sub
Private Sub Print_Record_Click()
On Error GoTo Err_Print_Record_Click


DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.PrintOut acSelection

Exit_Print_Record_Click:
Exit Sub

Err_Print_Record_Click:
MsgBox Err.Description
Resume Exit_Print_Record_Click

End Sub




Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.[Text31] = Time()

success = NetSendMsg("PRI Test Message", "D61PKFG1", "Please call me
ASAP")


End Sub

Private Sub Print_Form_Click()
On Error GoTo Err_Print_Form_Click


DoCmd.PrintOut

Exit_Print_Form_Click:
Exit Sub

Err_Print_Form_Click:
MsgBox Err.Description
Resume Exit_Print_Form_Click

End Sub
Private Sub Close_Form_Click()
On Error GoTo Err_Close_Form_Click


DoCmd.Close

Exit_Close_Form_Click:
Exit Sub

Err_Close_Form_Click:
MsgBox Err.Description
Resume Exit_Close_Form_Click

End Sub



Private Sub Refresh_data_Click()
On Error GoTo Err_Refresh_data_Click


DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70



Exit_Refresh_data_Click:
Exit Sub

Err_Refresh_data_Click:
MsgBox Err.Description
Resume Exit_Refresh_data_Click

End Sub
Private Sub Click_Here_for_Current_PRI_Totals_Click()
On Error GoTo Err_Click_Here_for_Current_PRI_Totals_Click

Dim stDocName As String

stDocName = "CURRENT"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_Click_Here_for_Current_PRI_Totals_C:
Exit Sub

Err_Click_Here_for_Current_PRI_Totals_Click:
MsgBox Err.Description
Resume Exit_Click_Here_for_Current_PRI_Totals_C

End Sub
****************************************************

Any suggestions for a newbie?

Thanks,
Eugene

Stuart McCall said:
Hello.
I have created an Access database that will be shared by a few people
that
will work almost as an Instant Messanger. The querey on the "Main" form
pulls
all records created by the person logged in to the computer (using a
module
that pulls the LAN login ID) and any record assigned to the person
logged
in.
The "Main" screen also refreshes automatically every 60 seconds.

I would like to add a feature and need your help. I need a pop up
window
to
appear indicating "A new task has been sent to you" and a beep sound
occur
when a person recieves a new record from someone else. This feature is
needed
since most folks have the access database minimized most of the time.

I was thinking of creating a "MsgBox" macro that would run on "After
Update"
of the "Main" form however since the person logged in will create
records
to
the MsgBox will appear everytime.

I would rather have it created in VB that does something like....

After Update on form "Main", If new record's "Assigned To" equals me
fOsUserName()

(fyi, I am currently using the fOsUserName() module which pulls the LAN
Login
ID and puts it into a different field called "Created By")

Then Run a MsgBox that says "A new task has been sent to you" with an
"OK"
button and with a beep sound.


Is this possible?

Your help is greatly appreciated.

Iram/mcp

The way I normally handle this is to use the API. You can try it by
grabbing
the code here:

http://www.smccall.demon.co.uk/MiscApi.htm#Netsend

The only caveat is that you need to know the user's machine name.


Did you place my code in a standard module (ie not a form or report module),
because that's where it needs to live. Also, what windows version are you
using?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top