How can make a msg box in a form where values are lookup from a table

yameen2011

Registered User.
Local time
Today, 06:19
Joined
Jan 19, 2013
Messages
59
Dear 4ndz i am working on a school database, in data base i have create two tables tblAccounts and tblTransaction and a form frmTransaction .
tblAccounts contain two fields
GLcodes
Description

and frmTransaction contain
Glcode
transaction type
debit
credit
date
narratives

in form when i enter a glcode, lookup field match the code from tblaccounts and shows the description in form against gl code.
But i am facing a problem when i enter a wrong gl code my form accept it and move to the next field and when i leave blank field of glcode same problem that i am facing, i want that , when i enter a wrong glcode in a form amsgbox will apear that asking for correct glcode.
i had attach screen shot of form and table.
kindly help me .
thanks.
sorry for my poor English .......:banghead:
 

Attachments

How do you decide when a wrong glcode has been entered?

Looks to me that all you need to do is change the text box for GLCode into a combo box with the following parameters:

rowsource "SELECT GLCode, Description FROM tblAccounts"
bound column: 1
column count: 2
column widths: 0cm;3cm
control source: GLCode
name: GLCode

and change the control source of the text box which has 'Generator Fuel' displaying in your screenshot to
Code:
=[GLCode].Column(1)
 
Thanks for answering me.
You don't understand that what i am trying to do. I don't want to change my "glcode" text box to combo box. my requirements in database is that user enter the glcode in text box instead of selecting from combo box.
I want to making that when i enter any gl code that is not exist in my
accounts table, or in the form i leave gl code blank , then a msgbox will appear that force user to enter correct GL Code and GL code field can't be null.
is their any vb coding or any macro in ms 2007.
Sample of my tbl & frm attached.
Waiting.
 

Attachments

Last edited:
OK - how do you populate the description box at the moment - you probably need to modify that code if a description is not found
 
hi,

how about this?

Private Sub GLcode_BeforeUpdate(Cancel As Integer)
If IsNull(DLookup("Glcode", "tblAccounts", "GLcode=" & Forms!frmTransaction!GLcode)) Then

MsgBox "Please enter correct GL account number!"
Cancel = True

End If
End Sub


Private Sub GLcode_LostFocus()
If IsNull(Me!GLcode) Then

MsgBox "GL account number should be entered!"

DoCmd.GoToControl ("TranxTypeID")
DoCmd.GoToControl ("GLcode")

End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom