Welcome to the { mindfrost82.com } forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Go Back   { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Access

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-09-2008, 01:33 AM
Bob Vance
 
Posts: n/a
Trouble with my VB Code

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

--
Thanks in advance for any help with this......Bob
WindowsXP..MS Access 2007


Reply With Quote
  #2 (permalink)  
Old 09-09-2008, 04:04 AM
JvC
 
Posts: n/a
Re: Trouble with my VB Code

Bob,

I suspect that cboHorseName and lbOwnerList are null, rather than 0, so
your code never runs. If you want to check for zero, you will need to
set the default for the fields to 0, and then run a query to update
them. The other thing you could do is check If IsNull(cboHorseName)
then, etc.

John

Bob Vance expressed precisely :
> 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



Reply With Quote
  #3 (permalink)  
Old 09-09-2008, 06:30 AM
=?Utf-8?B?U3RldmUgU2FuZm9yZA==?=
 
Posts: n/a
RE: Trouble with my VB Code

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" wrote:

> 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
>
> --
> Thanks in advance for any help with this......Bob
> WindowsXP..MS Access 2007
>
>
>

Reply With Quote
  #4 (permalink)  
Old 09-09-2008, 10:43 AM
Bob Vance
 
Posts: n/a
Re: Trouble with my VB Code

Steve BRILLIANT thank you for your effort your version 2 worked perfect
these are records already saved hence the No names in either combo or list
box
Couple of little bugs if you change the owner of a horse his old Invoice to
edit will not have his name, and the Owner Invoices are different as they do
not go through the horses name so need to alert the person opening the
Invoices to edit, Brilliant thanks Bob

"Steve Sanford" <limbim53 at yahoo dot com> wrote in message
news:095984C5-0BEB-4313-AF14-45EDE5851102@microsoft.com...
> 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" wrote:
>
>> 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
>>
>> --
>> Thanks in advance for any help with this......Bob
>> WindowsXP..MS Access 2007
>>
>>
>>



Reply With Quote
  #5 (permalink)  
Old 09-10-2008, 06:08 AM
=?Utf-8?B?U3RldmUgU2FuZm9yZA==?=
 
Posts: n/a
Re: Trouble with my VB Code

You're welcome...
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


"Bob Vance" wrote:

> Steve BRILLIANT thank you for your effort your version 2 worked perfect
> these are records already saved hence the No names in either combo or list
> box
> Couple of little bugs if you change the owner of a horse his old Invoice to
> edit will not have his name, and the Owner Invoices are different as they do
> not go through the horses name so need to alert the person opening the
> Invoices to edit, Brilliant thanks Bob
>
> "Steve Sanford" <limbim53 at yahoo dot com> wrote in message
> news:095984C5-0BEB-4313-AF14-45EDE5851102@microsoft.com...
> > 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" wrote:
> >
> >> 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
> >>
> >> --
> >> Thanks in advance for any help with this......Bob
> >> WindowsXP..MS Access 2007
> >>
> >>
> >>

>
>
>

Reply With Quote
Reply

  { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Access


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 04:25 PM.


Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
© 1999-2008 mindfrost82.com v11.0


Sponsors:
Credit Card Debt Consolidation | Advertising | Credit Cards | Babb Fest | Currency Converter



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114