PDA

View Full Version : Add form ID to be recognized on another form



daniels012
01-23-2008, 12:45 PM
I have a search form.
It finds company names of a repeat customers from a customer table TblCustomer

If 3 choices come up,
I want to be able to click on the one I want.
It then opens a form we have FrmRequestForWO
Then puts the ID number from TblCustomer to
FrmRequestForWO
When that is done all the appropriate fields would fill in as well ie:
Company name, address, City, State, etc. etc.

What code can i put to make the Id from one Go to the opening Form's ID.

Thank you for any help,
Michael

akn112
01-24-2008, 06:30 AM
Don't think i fully understand what your asking. But from what i think i got, you should look into the openargs property of a form. Also, is your search form using a list box? If so, it makes it easy because you can get your ID through lstMyList.column(Column#) (assuming it's shown on your list box)

daniels012
01-24-2008, 07:06 AM
ok,
Let me explain clearer.
Actually I have figured out on my search form how to get the "CAT" solution!!!!
2nd step I need help on is...

I have a Form called "FrmSearch"
The FrmSearch Form has let's say 4 results on the page.
I want to click the results I want. Let's call this "strSearchData" (This result is from a table "TblBillTo")
After I click one of the choices, i would like a Form called "FrmRequestForWO" to open and the strSearchData would be entered in the "BillToId" field on FrmRequestForWO. And then close the FrmSearch.

Does this make more sense?
Michael

akn112
01-24-2008, 07:54 AM
think i got it now. in frmSearch, when your opening your next form, write it like:

DoCmd.OpenForm "FrmRequestForWO", , , , , , strSearchData

In your frmRequestForWO form_load event write like:


public sub form_load
dim strID as string
strID = me.openargs
BillToId.value = strID
docmd.close acform, "frmSearch"
end sub


HTH

daniels012
01-24-2008, 11:00 AM
I got this to work thanks to you!
A couple of questions since I am learning as much as I can right now:
1)
What is openargs?
2)
What if i open the "FrmRequestForWO" without using the other form?
It then would open without openargs, right?

Could I bypass the openArgs part?

Something like:




Public Sub form_load
Dim strID As String
If OpenArgs.value = Null then Exit Sub
strID = me.openargs
BillToId.value = strID
docmd.close acform, "frmSearch"
End Sub


I am sure it's not that simple right?
Michael

akn112
01-24-2008, 11:22 AM
yeup, it is that simple. The way i usually set up my code is using the isnull statement

if isnull(me.openargs) then exit sub

Openargs is basically like the input parameters for a form, similar to the input parameters of a function. Another thing you can do with openargs is pass multiple parameters using the split function. For example


'Other form
Docmd.openform "myForm", , , , , , param1 & ";" & param2

'Loaded Form

public sub form_load
dim myOpenArgs as variant
dim parameter1 as string
dim parameter2 as string
myOpenArgs=split(me.openargs, ";")
parameter1 = myOpenArgs(0)
parameter2 = myopenArgs(1)
end sub



ps: treat openargs like any other string, int, etc. it does not have any properties attached to it (like .value)

daniels012
01-24-2008, 01:00 PM
Ok I think my problem is now, the FrmRequestForWO form
is wanting a number not the text I am transfering.

The "BillToID" is a number (even though it shows words)

Michael

akn112
01-24-2008, 01:50 PM
you will want to use the BillToID=clng(me.openargs) which converts it to a long type

daniels012
01-24-2008, 01:51 PM
Ok how and where do I do that?
Michael

I think it's looking for the BillToID that has a relationship to it???? Does this Matter?

akn112
01-24-2008, 01:57 PM
Something like:





Public Sub form_load


Dim lngID As long

If OpenArgs.value = Null then Exit Sub
lngID = clng(me.openargs)
BillToId.value = strID
docmd.close acform, "frmSearch"
End Sub

daniels012
01-24-2008, 02:07 PM
Here is the code:


Dim lngID As Long
If IsNull(Me.OpenArgs) Then Exit Sub
lngID = CLng(Me.OpenArgs)
BillToID.Value = lngID
DoCmd.Close acForm, "frmSearch"


I get a type mismatch error '13
:(
MIchael

daniels012
01-24-2008, 02:27 PM
When I am in error and I put my cursor over:
lngID it shows 0
If I hover over
Me.OpenArgs it shows "SFT Construction" (the name of the company)

daniels012
01-24-2008, 02:29 PM
It is on this line that the code stops:


lngID = CLng(Me.OpenArgs)

Michael

daniels012
01-25-2008, 06:40 AM
Why? can't I get past this?

Michael

akn112
01-25-2008, 06:51 AM
In your table, does it include an ID for each company? If so, you can try the dlookup function. Here is an example:

lngID = dlookup("[IDField]","TblCustomer","[CustomerName]= '" & me.openargs & "'"

daniels012
01-25-2008, 07:07 AM
Now, no error, but!!
nothing is showing? It has sometihng like the form was opened in the Windows bar, but my form doesn't show? Actually, I can't get the Access window to show anything but a windowed outline?

I will have to close the file.

This all may not be worth any of this!!
Michael

daniels012
01-25-2008, 07:39 AM
I think my file just does not want me passing data from one form to another.
I tried to move the OpenArgs to a textbox on the form. Same results, everything just locks up?

Michael

daniels012
01-25-2008, 08:45 AM
How about this:

I want a text box named [ChosenName] on my FrmRequestForWO to show the value in the textbox on my form FrmSearch [CoName]

How can I do this?
I don't think I even need code? Do I?
Michael

daniels012
01-25-2008, 08:53 AM
Actually i did this:


Private Sub BillToName_Click()
[ChosenName] = [BillToName]
End Sub


The problem is it erases when the form is closed. I want to copy it and have it stay in the ChosenName textbox.
How do I do that?

Michael

akn112
01-25-2008, 08:57 AM
if you are implementing it this way. I'd do it like the following:


1) docmd.openform "frmName"

2) in your form_load function do it this way:

public sub form_load
myTxtBox.value= Forms!frmSearch.BilltoName.value
docmd.close acform, "frmSearch"
end sub


You'd also have to account for if your opening your form without frmSearch being open. ie(: if currentprojects.allforms("frmSearch").isloaded then...)

daniels012
01-25-2008, 09:12 AM
I entered this:
If currentprojects.AllForms("FrmSearch").IsLoaded Then
I get an error 424
Object required

Michael

akn112
01-25-2008, 09:30 AM
sorry should be currentproject not currentprojects. Typing too fast =P

daniels012
01-25-2008, 09:38 AM
I did this:

if currentprojects.allforms("frmSearch").isloaded then


I looked in Help for IsLoaded and it really didn't show a good example, but it did use True/False, I tried that and that gave the same error.



I get Runtime error 424
Object required


i know you were giving me a sample but I just am not good at this stuff.

Michael

akn112
01-25-2008, 09:40 AM
your on the right path. it was my mistake, should be

If currentproject.allforms("frmSearch").isloaded Then

There is no 's' in currentproject

daniels012
01-25-2008, 09:42 AM
just got your message!
That worked!
Michael

daniels012
01-25-2008, 09:44 AM
Now,
Again, I have a problem.
All goes well.
I added a button to open the "FrmRequestForWO"
Now i have the same locking up going on????

Not sure what is going on??

Michael

akn112
01-25-2008, 09:45 AM
hmm...im not sure what you mean by locking up, would it be possible to post a sanitized version of your database so i can take a look? thanks.

daniels012
01-25-2008, 09:55 AM
I can post the whole thing if you want?
we don't do anything sanitized!?! LOL
Michael

akn112
01-25-2008, 11:02 AM
whole thing would be good. You'll have to zip it first though

daniels012
01-25-2008, 11:41 AM
Ok here is the attached file.

I can't send the BackEnd File that goes with it, because
it is way too large, but you can add a couple of records to
get the idea.

Thank You,
Michael

daniels012
01-25-2008, 11:46 AM
I may be able to email you the back end if you like!
Michael

akn112
01-25-2008, 12:23 PM
could you attach the a copy of your backend with just a couple entries?

daniels012
01-28-2008, 06:38 AM
How exactly should I do this? I would have to make a copy of my database, somehow delete 1200 records, then delete about 670 contacts?
Is this correct?

Michael

akn112
01-28-2008, 07:29 AM
Hey Michael, You'd have to create a copy of your Backend, delete all the records while keeping the structure of the table and maybe add 1 or 2 examples.