How to force to pass value from one form into the other?

  • Thread starter Alex via AccessMonster.com
  • Start date
A

Alex via AccessMonster.com

Hi all. Thanks for your helping me in the recent months, great forum.

Now for problem, I've got a query that lists ID numbers of employees. When
I double click on ID number I need that ID number to be passed on to
another form to look the details of that employee. The employee ID is a
"number", not autonumber, but can't be edited in a form.
Currently, when I double click it doesn't pass the value (OpenArgs method),
but opens 1st record with different empID

Any ideas on how to overcome this?
Thanks
 
G

Guest

You could use the where arguments when you open a form


docmd.OpenForm "YourForm",WhereCondition:="Employee_Number=" &
me.Employee_Number

You only have to make sure that the form that you are opening contains the
field in the recordsource
 
A

Alex via AccessMonster.com

Hey, thanks Jara, works wonders! But I just stumbled across another need.

I need help with the "If" statement. Say I have SourceID,
if SourceID=1 then open form as stated above with "where clause". If
SourceID=2,3,4 or 5 open another form. I need to implement that "If"
statement somehow. Sorry, just started VB

Thanks
 
G

Guest

Beter to use select case

code :

Select Case SourceId
case 1:
' Do Something
case 2, 3:
' Do Something
case else:
' Do default something
End Select
 
A

Alex via AccessMonster.com

Hmmm, it doesn't seem to work on double click, maybe I am doing something
wrong, the code I've got:
---
Private Sub comment_id_DblClick(Cancel As Integer)
Select Case source_id
Case 1:
DoCmd.OpenForm "PhoneComments", WhereCondition:="source_id=1,2,3,4" &
"comment_id=" & Me.comment_id
Case 2, 3:
DoCmd.OpenForm "CommentCard", WhereCondition:="source_id=5" &
"comment_id=" & Me.comment_id
End Select
End Sub
 
S

Steven Greenberg

Hmmm, it doesn't seem to work on double click, maybe I am doing something
wrong, the code I've got:
---
Private Sub comment_id_DblClick(Cancel As Integer)
Select Case source_id
Case 1:
DoCmd.OpenForm "PhoneComments", WhereCondition:="source_id=1,2,3,4" &
"comment_id=" & Me.comment_id
Case 2, 3:
DoCmd.OpenForm "CommentCard", WhereCondition:="source_id=5" &
"comment_id=" & Me.comment_id
End Select
End Sub

Try it without the colons after the case 1: <-
I don't know if the colon is optional or not, but I have never used one in
any select case statement nor have ever seen one in any text I have read.
 
G

Guest

Indeed no colons, now a days I switch to much between VBA and C#
Sorry :)

I hope the implement c# soon for accesss LOL
 
A

Alex via AccessMonster.com

Ummm, this seems to be the way it was, it just doesn't do anything (double
click isn't working), although there is a field "source_id" for code
reference. It seems to me it can't trigger the code at the moment:
-----
Private Sub comment_id_DblClick(Cancel As Integer)
Select Case source_id
Case 1
DoCmd.OpenForm "PhoneComments", WhereCondition:="source_id=1 or
source_id=2 or source_id=3 or source_id=4" & "comment_id=" & Me.comment_id
Case 2
DoCmd.OpenForm "CommentCard", WhereCondition:="source_id=5" &
"comment_id=" & Me.comment_id
End Select
End Sub
 
G

Guest

The code should be:
Always try to capitalize the SQL syntax words makes everything a bit more
readable. But you were missing the AND before comment_ID

Private Sub comment_id_DblClick(Cancel As Integer)
Select Case source_id
Case 1
DoCmd.OpenForm "PhoneComments", WhereCondition:="source_id=1 OR
source_id=2 OR source_id=3 OR source_id=4 AND comment_id=" & Me.comment_id
Case 2
DoCmd.OpenForm "CommentCard", WhereCondition:="source_id=5 AND
comment_id=" & Me.comment_id
End Select
End Sub
 

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