Help with opening a form to a specific record

D

DawnTreader

Hello All

does anyone see anything wrong with this code on a list box that opens a
popup form to a specific record:

Private Sub lstWarnings_DblClick(Cancel As Integer)
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "pfrmWarnings"
stLinkCriteria = "[WarningID]=" & Me.lstWarnings.Column(0)
MsgBox stLinkCriteria
DoCmd.OpenForm stDocName, , , stLinkCriteria, , , "Opened"
End Sub

and here is the code that happens as the form loads:

Private Sub Form_Load()
MsgBox Me.OpenArgs
Select Case Me.OpenArgs
Case "New"
Me.DataEntry = True
Me.Cycle = 0
Me.AllowAdditions = True
Me.txtSerialNumber.Requery
Me.cmdDeleteWarning.Visible = False
Me.cmdWarningFinished.Visible = False
Case "Opened"
Me.DataEntry = False
Me.Cycle = 1
Me.AllowAdditions = False
Me.txtSerialNumber.Requery
Me.cmdDeleteWarning.Visible = True
Me.cmdWarningFinished.Visible = True
Case Else
End Select
End Sub


does any one see something that i dont that would cause the form to not open
on the record specified in the stLinkCriteria variable? i have been fighting
this for days... :(
 
J

Jack Leach

I don't see anything amiss in the syntax of the code you've supplied. That
leaves verifying the value of your list box... is it the same datatype/value
as the field in the record you're trying to open to?

Note that if the value is a string datatype you would need to modify the
criteria (add quotes), but if it's a number you should be fine just like you
are.

If it is a string, try this:

stLinkCriteria = "[WarningID]=""" & Me.lstWarnings.Column(0) & """"



You can also, for verification purposes, put the value of the listbox into a
variable before you set the stLinkCriteria string so you can verify the data
in it...

Dim lngListValue As Long
lngListValue = Me.lstWarnings.Column(0)
Debug.Print lngListValue
stLinkCriteria = "[WarningID]=" & lngListValue


hth

--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
D

Douglas J. Steele

Does it open the form to the incorrect record, or does it display all
records?

Does the message box display the correct id?

Any error messages?
 
D

DawnTreader

Hello Jack and Doug

it is an autonumber field. the message box is to verify the data going in...
:) i use that instead of a debug. it allows me to have it come up when the
value is made as well. kind of a pause.

it opens to the first record and displays all. the message box does display
the right id. no error messages.

Douglas J. Steele said:
Does it open the form to the incorrect record, or does it display all
records?

Does the message box display the correct id?

Any error messages?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


DawnTreader said:
Hello All

does anyone see anything wrong with this code on a list box that opens a
popup form to a specific record:

Private Sub lstWarnings_DblClick(Cancel As Integer)
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "pfrmWarnings"
stLinkCriteria = "[WarningID]=" & Me.lstWarnings.Column(0)
MsgBox stLinkCriteria
DoCmd.OpenForm stDocName, , , stLinkCriteria, , , "Opened"
End Sub

and here is the code that happens as the form loads:

Private Sub Form_Load()
MsgBox Me.OpenArgs
Select Case Me.OpenArgs
Case "New"
Me.DataEntry = True
Me.Cycle = 0
Me.AllowAdditions = True
Me.txtSerialNumber.Requery
Me.cmdDeleteWarning.Visible = False
Me.cmdWarningFinished.Visible = False
Case "Opened"
Me.DataEntry = False
Me.Cycle = 1
Me.AllowAdditions = False
Me.txtSerialNumber.Requery
Me.cmdDeleteWarning.Visible = True
Me.cmdWarningFinished.Visible = True
Case Else
End Select
End Sub


does any one see something that i dont that would cause the form to not
open
on the record specified in the stLinkCriteria variable? i have been
fighting
this for days... :(
 
J

Jack Leach

Do you have any other code in the target form's Open or Current events that
may have an alternative effect on the form's current record or recordsource?

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)



DawnTreader said:
Hello Jack and Doug

it is an autonumber field. the message box is to verify the data going in...
:) i use that instead of a debug. it allows me to have it come up when the
value is made as well. kind of a pause.

it opens to the first record and displays all. the message box does display
the right id. no error messages.

Douglas J. Steele said:
Does it open the form to the incorrect record, or does it display all
records?

Does the message box display the correct id?

Any error messages?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


DawnTreader said:
Hello All

does anyone see anything wrong with this code on a list box that opens a
popup form to a specific record:

Private Sub lstWarnings_DblClick(Cancel As Integer)
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "pfrmWarnings"
stLinkCriteria = "[WarningID]=" & Me.lstWarnings.Column(0)
MsgBox stLinkCriteria
DoCmd.OpenForm stDocName, , , stLinkCriteria, , , "Opened"
End Sub

and here is the code that happens as the form loads:

Private Sub Form_Load()
MsgBox Me.OpenArgs
Select Case Me.OpenArgs
Case "New"
Me.DataEntry = True
Me.Cycle = 0
Me.AllowAdditions = True
Me.txtSerialNumber.Requery
Me.cmdDeleteWarning.Visible = False
Me.cmdWarningFinished.Visible = False
Case "Opened"
Me.DataEntry = False
Me.Cycle = 1
Me.AllowAdditions = False
Me.txtSerialNumber.Requery
Me.cmdDeleteWarning.Visible = True
Me.cmdWarningFinished.Visible = True
Case Else
End Select
End Sub


does any one see something that i dont that would cause the form to not
open
on the record specified in the stLinkCriteria variable? i have been
fighting
this for days... :(
 
D

DawnTreader

Hello Jack

the only thing i have in the open event is:

DoCmd.MoveSize 100, 100

could i have the cycles backawards?

Case "New"
Me.DataEntry = True
Me.Cycle = 0 ' should this be 1?
Me.AllowAdditions = True
Me.txtSerialNumber.Requery
Me.cmdDeleteWarning.Visible = False
Me.cmdWarningFinished.Visible = False
Case "Opened"
Me.DataEntry = False
Me.Cycle = 1 ' should this be 0?
Me.AllowAdditions = False
Me.txtSerialNumber.Requery
Me.cmdDeleteWarning.Visible = True
Me.cmdWarningFinished.Visible = True

going to test that.

Jack Leach said:
Do you have any other code in the target form's Open or Current events that
may have an alternative effect on the form's current record or recordsource?

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)



DawnTreader said:
Hello Jack and Doug

it is an autonumber field. the message box is to verify the data going in...
:) i use that instead of a debug. it allows me to have it come up when the
value is made as well. kind of a pause.

it opens to the first record and displays all. the message box does display
the right id. no error messages.

Douglas J. Steele said:
Does it open the form to the incorrect record, or does it display all
records?

Does the message box display the correct id?

Any error messages?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Hello All

does anyone see anything wrong with this code on a list box that opens a
popup form to a specific record:

Private Sub lstWarnings_DblClick(Cancel As Integer)
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "pfrmWarnings"
stLinkCriteria = "[WarningID]=" & Me.lstWarnings.Column(0)
MsgBox stLinkCriteria
DoCmd.OpenForm stDocName, , , stLinkCriteria, , , "Opened"
End Sub

and here is the code that happens as the form loads:

Private Sub Form_Load()
MsgBox Me.OpenArgs
Select Case Me.OpenArgs
Case "New"
Me.DataEntry = True
Me.Cycle = 0
Me.AllowAdditions = True
Me.txtSerialNumber.Requery
Me.cmdDeleteWarning.Visible = False
Me.cmdWarningFinished.Visible = False
Case "Opened"
Me.DataEntry = False
Me.Cycle = 1
Me.AllowAdditions = False
Me.txtSerialNumber.Requery
Me.cmdDeleteWarning.Visible = True
Me.cmdWarningFinished.Visible = True
Case Else
End Select
End Sub


does any one see something that i dont that would cause the form to not
open
on the record specified in the stLinkCriteria variable? i have been
fighting
this for days... :(
 
D

DawnTreader

Hello

i not only tried it with the 1 and 0 on the reverse, i also cleared out a
few lines to see if they were just getting in the way.

Case "New"
Me.DataEntry = True
' Me.NavigationButtons = False
' Me.Cycle = 1 ' originally 0
Me.AllowAdditions = True
Me.txtSerialNumber.Requery
Me.cmdDeleteWarning.Visible = False
Me.cmdWarningFinished.Visible = False
Case "Opened"
' Me.NavigationButtons = False
Me.DataEntry = False
' Me.Cycle = 0 ' originally 1
Me.AllowAdditions = False
Me.txtSerialNumber.Requery
Me.cmdDeleteWarning.Visible = True
Me.cmdWarningFinished.Visible = True


i even changed the record source to be the table and it still acted this way.

help.


DawnTreader said:
Hello Jack

the only thing i have in the open event is:

DoCmd.MoveSize 100, 100

could i have the cycles backawards?

Case "New"
Me.DataEntry = True
Me.Cycle = 0 ' should this be 1?
Me.AllowAdditions = True
Me.txtSerialNumber.Requery
Me.cmdDeleteWarning.Visible = False
Me.cmdWarningFinished.Visible = False
Case "Opened"
Me.DataEntry = False
Me.Cycle = 1 ' should this be 0?
Me.AllowAdditions = False
Me.txtSerialNumber.Requery
Me.cmdDeleteWarning.Visible = True
Me.cmdWarningFinished.Visible = True

going to test that.

Jack Leach said:
Do you have any other code in the target form's Open or Current events that
may have an alternative effect on the form's current record or recordsource?

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)



DawnTreader said:
Hello Jack and Doug

it is an autonumber field. the message box is to verify the data going in...
:) i use that instead of a debug. it allows me to have it come up when the
value is made as well. kind of a pause.

it opens to the first record and displays all. the message box does display
the right id. no error messages.

:

Does it open the form to the incorrect record, or does it display all
records?

Does the message box display the correct id?

Any error messages?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Hello All

does anyone see anything wrong with this code on a list box that opens a
popup form to a specific record:

Private Sub lstWarnings_DblClick(Cancel As Integer)
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "pfrmWarnings"
stLinkCriteria = "[WarningID]=" & Me.lstWarnings.Column(0)
MsgBox stLinkCriteria
DoCmd.OpenForm stDocName, , , stLinkCriteria, , , "Opened"
End Sub

and here is the code that happens as the form loads:

Private Sub Form_Load()
MsgBox Me.OpenArgs
Select Case Me.OpenArgs
Case "New"
Me.DataEntry = True
Me.Cycle = 0
Me.AllowAdditions = True
Me.txtSerialNumber.Requery
Me.cmdDeleteWarning.Visible = False
Me.cmdWarningFinished.Visible = False
Case "Opened"
Me.DataEntry = False
Me.Cycle = 1
Me.AllowAdditions = False
Me.txtSerialNumber.Requery
Me.cmdDeleteWarning.Visible = True
Me.cmdWarningFinished.Visible = True
Case Else
End Select
End Sub


does any one see something that i dont that would cause the form to not
open
on the record specified in the stLinkCriteria variable? i have been
fighting
this for days... :(
 
J

Jack Leach

Something's not adding up here. Your case statement itself should have
nothing to do with the issue, let alone the order of it. It's not like you
have any navigation code inside the select statement, so I can't see where
that would change anything.

Try it out from scratch no a fresh table(s) and form(s) with only 4 or 5
fake records. Get it to work, then compare everything to your current
situation. Something's messing up the works, I can't relly see what.
There's got to be something else aside from what I'm not seeing.

I'll do this a lot if I can't seem to get something. Start from scratch and
make up a sample just to test the particular method. Get it to work, and
compare with the real requirement.

hth
--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)



DawnTreader said:
Hello

i not only tried it with the 1 and 0 on the reverse, i also cleared out a
few lines to see if they were just getting in the way.

Case "New"
Me.DataEntry = True
' Me.NavigationButtons = False
' Me.Cycle = 1 ' originally 0
Me.AllowAdditions = True
Me.txtSerialNumber.Requery
Me.cmdDeleteWarning.Visible = False
Me.cmdWarningFinished.Visible = False
Case "Opened"
' Me.NavigationButtons = False
Me.DataEntry = False
' Me.Cycle = 0 ' originally 1
Me.AllowAdditions = False
Me.txtSerialNumber.Requery
Me.cmdDeleteWarning.Visible = True
Me.cmdWarningFinished.Visible = True


i even changed the record source to be the table and it still acted this way.

help.


DawnTreader said:
Hello Jack

the only thing i have in the open event is:

DoCmd.MoveSize 100, 100

could i have the cycles backawards?

Case "New"
Me.DataEntry = True
Me.Cycle = 0 ' should this be 1?
Me.AllowAdditions = True
Me.txtSerialNumber.Requery
Me.cmdDeleteWarning.Visible = False
Me.cmdWarningFinished.Visible = False
Case "Opened"
Me.DataEntry = False
Me.Cycle = 1 ' should this be 0?
Me.AllowAdditions = False
Me.txtSerialNumber.Requery
Me.cmdDeleteWarning.Visible = True
Me.cmdWarningFinished.Visible = True

going to test that.

Jack Leach said:
Do you have any other code in the target form's Open or Current events that
may have an alternative effect on the form's current record or recordsource?

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)



:

Hello Jack and Doug

it is an autonumber field. the message box is to verify the data going in...
:) i use that instead of a debug. it allows me to have it come up when the
value is made as well. kind of a pause.

it opens to the first record and displays all. the message box does display
the right id. no error messages.

:

Does it open the form to the incorrect record, or does it display all
records?

Does the message box display the correct id?

Any error messages?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Hello All

does anyone see anything wrong with this code on a list box that opens a
popup form to a specific record:

Private Sub lstWarnings_DblClick(Cancel As Integer)
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "pfrmWarnings"
stLinkCriteria = "[WarningID]=" & Me.lstWarnings.Column(0)
MsgBox stLinkCriteria
DoCmd.OpenForm stDocName, , , stLinkCriteria, , , "Opened"
End Sub

and here is the code that happens as the form loads:

Private Sub Form_Load()
MsgBox Me.OpenArgs
Select Case Me.OpenArgs
Case "New"
Me.DataEntry = True
Me.Cycle = 0
Me.AllowAdditions = True
Me.txtSerialNumber.Requery
Me.cmdDeleteWarning.Visible = False
Me.cmdWarningFinished.Visible = False
Case "Opened"
Me.DataEntry = False
Me.Cycle = 1
Me.AllowAdditions = False
Me.txtSerialNumber.Requery
Me.cmdDeleteWarning.Visible = True
Me.cmdWarningFinished.Visible = True
Case Else
End Select
End Sub


does any one see something that i dont that would cause the form to not
open
on the record specified in the stLinkCriteria variable? i have been
fighting
this for days... :(
 

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