What is wrong with this? (1 Viewer)

Lady Gragor

Registered User.
Local time
Today, 09:15
Joined
Nov 4, 2008
Messages
37
I'm having a referencing problem. This is not working. The after update event is on a control located on subform 2.

Private Sub JobNo_AfterUpdate()
If Me!JobNo = "4999" And Forms![frm_Vehicle]![VehicleTimesheetSubFrm]![Driver] = "Person's Name" Then
MsgBox "A Message"
End If
 

jhuncabas

New member
Local time
Yesterday, 16:15
Joined
Nov 29, 2008
Messages
1
Hi

I have a form where I enter customer orders, the main form containing customer name address etc.

On this form I have a sub form which holds the individual lines of the order, partno, qty etc.

I need to number these lines starting at 1 for each new order, and increasing for each line of the order.

I can get it to work correctly from line 3 onwards, but I get 2 for the first two lines. I have tried using the value currentrecord and adding 1 , but as I am line 1 when I set the value for line 1 it gives 2, and if I don't add 1 each line number is 1 too low.

Any ideas?

jhun
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 00:15
Joined
Sep 12, 2006
Messages
15,634
a few possible things wrong with this, on the face of it

first, if jobno is a number, then you dont need to enclose it in quote marks

so
If Me!JobNo = 4999 And Forms![frm_Vehicle]![VehicleTimesheetSubFrm]![Driver] = "Person's Name" Then

now "persons name" will specfiically look for a value called "person's name", if instead you are looking for the value of a FIELD called person's name, then, if it has a space you need to enclose it in square brackets

so now we get

If Me!JobNo = 4999 And Forms![frm_Vehicle]![VehicleTimesheetSubFrm]![Driver] = [Person's Name] Then

however, i suspect that your field [persons name] does NOT have the apostrophe in it, as I am pretty sure that is an illlegal character in a field name
 
Last edited:

ShaneMan

Registered User.
Local time
Yesterday, 16:15
Joined
May 9, 2005
Messages
1,224
I'm having a referencing problem. This is not working. The after update event is on a control located on subform 2.

Private Sub JobNo_AfterUpdate()
If Me!JobNo = "4999" And Forms![frm_Vehicle]![VehicleTimesheetSubFrm]![Driver] = "Person's Name" Then
MsgBox "A Message"
End If

You need to reference the subform a little further.

If Me!JobNo = 4999 And Forms![frm_Vehicle]![VehicleTimesheetSubFrm].Form![Driver] = "Person's Name" Then

also, if "Person's Name" is a text control that your referencing then I believe you will also need to go a little further with it and do something like this:

If Me!JobNo = 4999 And Forms![frm_Vehicle]![VehicleTimesheetSubFrm].Form![Driver] ='" & Me.[NameOfControlWithPerson'sName] & "'" Then

HTH,
Shane
 

Lady Gragor

Registered User.
Local time
Today, 09:15
Joined
Nov 4, 2008
Messages
37
Thank you for your suggestions.

If Me!JobNo = 4999 I know this part works.

I have tried your suggestions with the following but still having a problem

And Forms![frm_Vehicle]![VehicleTimesheetSubFrm]![Driver] = "Person's Name" Then ....

"Person's Name" is the name of a peson displayed in the field named 'Driver'
 

WayneRyan

AWF VIP
Local time
Today, 00:15
Joined
Nov 19, 2002
Messages
7,122
Lady,

"Person's Name" is the name of a peson displayed in the field named 'Driver'


Code:
And Forms![frm_Vehicle]![VehicleTimesheetSubFrm].Form![Driver] = "Person's Name"
                                                                        ^
                                                                        |
                              This is in a field named 'Driver' ???   --+

So, you're comparing two different controls to see if they're the same.

The left one obviously lives on the VehicleTimesheetSubFrm as the field [Driver]

Is the Right one on the main form --> Forms![frm_Vehicle]![Driver]

Wayne
 

Lady Gragor

Registered User.
Local time
Today, 09:15
Joined
Nov 4, 2008
Messages
37
Wayne,

There are two sub forms.
In a control on subform 2 in the after update event, I'm saying if the value is 4999 then check subform 1 to see if the driver is equal to "Name" in the field named Driver. If it is, then give the message.

Lady
 

CyberLynx

Stuck On My Opinions
Local time
Yesterday, 16:15
Joined
Jan 31, 2008
Messages
585
It's just that hard coding a name into your code is rather odd. Normally you would reference another control which contains the name to compare to but to each their own.

Try this:

Code:
If Me.JobNo = 4999 And Forms("frm_Vehicle")("VehicleTimesheetSubFrm").Form.Driver.Value = "Persons Name" Then

Where:

frm_Vehicle is the name of the Main Form

and

VehicleTimesheetSubFrm is then name of the Sub-Form Control loacted on the Main Form. Not the SubForm Form name but the Control Name that is housing the Sub-Form.

and

Driver is a TextBox or ComboBox located within that SubForm.

.
 

Lady Gragor

Registered User.
Local time
Today, 09:15
Joined
Nov 4, 2008
Messages
37
If I do this..

Private Sub JobNo_AfterUpdate()

If Me!JobNo = 4999 Then

MsgBox "Is 4999"

If Forms("frm_Vehicle").Controls("Vehicle_SubFrm").Form.Controls("Driver").Value = "Noddy" Then
MsgBox "This is Noddy"

Else

MsgBox "Yeah it works"

End If
End If

End Sub

It will now compile. I get the messages "Is 4999" and "Yeah it works" but nothing about Noddy.
 

Users who are viewing this thread

Top Bottom