Hi Bob,
Here are some of my thoughts and observsations:
"Value" is the default property for a textbox (as in
tbCompanyName.value)...
you do not have to have it (saves typing).
------------
It looks like you have at combo box named "cbHorseName" and a list box
named
"lbOwnerList". Is the bound column for the combo box and the list box a
long
integer (and the PK)? Or is the bound column a string?
If the bound column is an integer, to check if a horse name was selected,
I
would use:
If Nz(cbHorseName,0) = 0 Then
The function Nz() (Null to Zero) converts a Null to (in this case) a 0
(Zero)
If the bound column is an string, to check if a horse name was selected, I
would use:
If Len(Nz(cbHorseName,"")) = 0 Then
Here I am using the Nz() function to convert a Null to an empty string,
then
using the Len() function to check the length of the variable value.
------------
If cbHorseName = 0 & lbOwnerList = 0 Then
In this (nested) If() function, you are using a string concatenation
operator (&) between the variables instead of the "And" operator. The
statement should be:
If cbHorseName = 0 AND lbOwnerList = 0 Then
Also, the first expression, "cbHorseName = 0", is not necessary, because
you
already checked for the HorseName in the outer If() function...(but it
doesn't hurt anything).
Note that if a horse name was selected, the check for the owner name
(lbOwnerList = 0) would never occur.
------------
tbCompanyName.value = DLookup("CompanyName", "tblCompanyInfo")
The syntax for the DLookup() function is: DLookup(expr, domain,
[criteria])
While the criteria caluse is optional, this is what help says:
"The DLookup function returns a single field value based on the
information
specified in criteria. Although criteria is an optional argument, *if you
don't supply a value for criteria, the DLookup function returns a random
value in the domain.*"
Unless you have only one company name in the table, using the DLookup()
function like you have it will result in a random company name being
entered
in the [tbCompanyName] control.
------------
Here are two versions of your code:
'--- VERSION 1 ---
Private Sub Form_Load()
DoCmd.Maximize
On Error Resume Next
' ------ this needs a criteria clause
Me.tbCompanyName = DLookup("CompanyName", "tblCompanyInfo")
'-------
If Nz(Me.cbHorseName,0) = 0 Then
MsgBox "(Client Invoice) Must be Edited from Main Menu/Client
Invoices! "
If Nz(Me.lbOwnerList,0) = 0 Then
MsgBox "(No Owner) ! "
End If
End If
End Sub
'--- VERSION 2---
Private Sub Form_Load()
DoCmd.Maximize
On Error Resume Next
' ------ this needs a criteria clause
Me.tbCompanyName = DLookup("CompanyName", "tblCompanyInfo")
'-------
' check for horse name
If Nz(Me.cbHorseName,0) = 0 Then
MsgBox "(Client Invoice) Must be Edited from Main Menu/Client
Invoices! "
'check for owner name
ElseIf Nz(Me.lbOwnerList,0) = 0 Then
MsgBox "(No Owner) ! "
End If
End Sub
'--------------------
I can't help but wonder why this code is in the form load event. If the
form
is used to enter new records, won't [cbHorseName] and [lbOwnerList] always
be
NULL? If the form has a recordsource, won't the [cbHorseName] and
[lbOwnerList] have values?
HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)
Bob Vance said:
I can get the first part of my code to work when the Combo box
cbHorseName
is empty I get the Message but I cant get cbHorseName & List Box
lbOwnerlist
to work, actually lbOwnerList wont even work it self......Thanks Bob
Private Sub Form_Load()
DoCmd.Maximize
On Error Resume Next
tbCompanyName.value = DLookup("CompanyName", "tblCompanyInfo")
If cbHorseName = 0 Then
MsgBox "(Client Invoice) Must be Edited from Main
Menu/Client Invoices! "
If cbHorseName = 0 & lbOwnerList = 0 Then
MsgBox "(No Owner) ! "
End If
End If
End Sub