Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Link between forms based on Criteria

Status
Not open for further replies.

Silvertri

Programmer
Aug 26, 2002
21
AU
We are converting an Access based App to .Net with little or no VB knowledge . The following is an access connection string we use extensively to link to forms based on a field value on main form. Can anybody kindly provide the equivalent. I presume you use response.redirect but am unsure of syntax ...TIA Silvertri
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmCtlMainRequestAssistance"

stLinkCriteria = "[IncidentName]=" & Me![IncidentName]
DoCmd.OpenForm stDocName, , , stLinkCriteria
 
You mention "Response.Redirect" Are you converting this to an ASP.net application using VB.Net? If so you can use a number of different methods. Request.Querystring, Request.Form, or even javascript. Let me know what you are using.
 
Yes we are converting to ASP.Net using VB.Net

However we are using a tool from which basically does the form conversion , we are then left with the reconnection between forms and subsequently things like after update queries that need to be reinstated once they are converted to server side which I am in process with at them moment.. Hope this gives an overview of the process

Cheers Silvertri
 
The one thing you will have to worry about is State. Access has State. ASP.net does not.

Going off of your code above the conversion to ASP.net would be the following.


Response.Redirect("frmCtlMainRequestAssistance.aspx?IncidentName=" & IName )

'IName being the name or number of your incedent.
'On the page you are sending this too you will
'have to collect it using

Dim Incident as string
Incident = Request.QueryString("IName")

Again remember to be aware of the statelessness of ASP.net

Hope this helps. If you need more detail let me know
 
The code compilies correctly but does bot excute

Sub Button1_Click(sender As Object, e As EventArgs)
Response.Redirect("frmOperationsOfficer.aspx?IncidentNameAlpha="& "IName")
End Sub

Private Sub Page_Load(sender As object, e As System.EventArgs)
Dim IncidentNameAlpha as string
IncidentNameAlpha = Request.QueryString("IName")


Have I gone about this correctly

You also mentioned the state.

Regards
Dallas

 
First question: When the tool you are using converts the page does it just create an .aspx page or does it create the code behind page(.asps.vb) as well.

Second:
In your code above you have
Response.Redirect("frmOperationsOfficer.aspx?IncidentNameAlpha="& "IName")

It should be
Response.Redirect("frmOperationsOfficer.aspx?IncidentNameAlpha="& IName)

IName is a variable not a string

The more code you can post here from the page the better I can understand what you are doing and show you how to fix it.
 
When viewed in web matrix the vb code appears thru the code tab
and ditto for the html code there is no separate vb file created.

For clarification we have two fields incidentnamealpha (text) and
incidentname (integer) when we converted to a SQL backend we
implemented incidentname for improved performance if we get a
large client all our forms are linked this way then contain subforms with related data.
we have standardized the link between forms on
IncidentName but my son (works remotely)
was trying IncidentnameAlpha as well.. not the preferred option.

I have attached the mods we have done to connection string for you
to check
'SQL connection
databasespec="Provider=Sqloledb;Data Source=(Local);Initial Catalog=AIMSxpSQL;integrated security = SSPI"
keyname="IncidentName"
'SQL Control Source
controlsource ="SELECT *FROM dbo.tblMainDetails"


This is the current form link (the other forms work oK when opened directly)


Sub BtnRequestAssistance_Click(sender As object,e As System.EventArgs)
Response.Redirect("frmCtlMainRequestAssistance.aspx?IncidentName=" & IName )
End Sub

Are we getting a clash from the select command already on the second form?

controlsource ="SELECT *FROM dbo.tblMainDetails"

Does the Request.QueryString replace it when linked from Main form

This is the Page Load section on a second form as per the above example
with your suggested code at top

Private Sub Page_Load(sender As object, e As System.EventArgs)
Dim Incident as Integer
Incident = Request.QueryString("IName")

If(Not IsPostBack)Then
Call SetDataFile()
ButtonFirst.Enabled=ButtonLast.Enabled=True
xnrs=OpenDatabaseX(controlsource,databasespec)
xcurr=0
Call SetComboBoxes(-1)
Call SetListBoxes(-1)
Selection.Text=""
Call SetKeyList()
ithrec=0
If(xmrs>0)Then
ithrec=1
xKeyList.SelectedIndex=0
xcurr=GetIndex(ithrec)
Call FillForm(xcurr)
ButtonPrev.Enabled=False
End If
Labeltotal.Text=" of " & xmrs.ToString()
End If
End Sub
Sub ButtonClose_Click(sender As object, e As System.EventArgs)
Try
xdatamode=0
If(Not IsDBNull(Request.Params("u")))Then Server.Transfer(Request.Params("u") & ".aspx")
Catch ex As Exception
End Try
End Sub

I hope this helps....Cheers Ken
 
First lets start with the button click When you click on
the btnRequestAssitance Button it should take you to frmCtlMainRequestAssistance.aspx.

Does it do this?


Sub BtnRequestAssistance_Click(sender As object,e As System.EventArgs)
Response.Redirect("frmCtlMainRequestAssistance.aspx?IncidentName=" & IName )
End Sub


DotNetDoc
M.C.S.D.

A common mistake people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
- D. Adams

--------------------------------------


 
In a word no it simply comes with page cannot be displayed invaild syntax
 
Do you have a form called "frmCtlMainRequestAssistance.aspx" or is this supposed to be dynamic as well?

Sub BtnRequestAssistance_Click(sender As object,e As System.EventArgs)
Response.Redirect("frmCtlMainRequestAssistance.aspx?IncidentName=" & IName )
End Sub


DotNetDoc
M.C.S.D.
---------------------------------------

Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb

-----------------------------------

If you can't explain it simply, you don't understand it well enough.
- A. Einstein





 
Yes we have form of this name and it opens directly without problem.

Also another form frmParametersMenu which opens from our main form OK with the following code but without the IncidentName link (not required for this area of application)

Sub BntParameters_Click(sender As object,e As System.EventArgs)
Response.Redirect ("frmParametersMenu.aspx")
End Sub

 
After you click on the button Copy and paste into here two things:

1.) The Url from the address line

2.) The whole text on the page. Error and all.

Sorry this is taking so long. It is hard when you cannot be there to see it. The code you are posting in is correct so it has to be a small syntax error.

DotNetDoc
M.C.S.D.
---------------------------------------

Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb

-----------------------------------

If you can't explain it simply, you don't understand it well enough.
- A. Einstein





 
When the tool converts the Access form it creates .aspx file no .vb class. We view and edit the code using web matrix.


Your posted code
------------------------------------------------------------
Sub BtnRequestAssistance_Click(sender As object,e As System.EventArgs)
Response.Redirect("frmCtlMainRequestAssistance.aspx?IncidentName=" & IName )
End Sub

------------------------------------------------------------

Server Error in '/' Application.
--------------------------------------------------------------------------------

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'IName' is not declared.

Source Error:



Line 2198:
Line 2199: Sub Button1_Click(sender As Object, e As EventArgs)
Line 2200: Response.Redirect("frmOperationsOfficer.aspx?IncidentNameAlpha=" & IName )
Line 2201: End Sub
Line 2202:


Source File: C:\Aims Production\AIMS .NET\frmCtlIncidentMain.aspx Line: 2200


Hope this helps you/us

Regards
Dallas

--------------
 
You are getting the error because IName has not been declared as a variable.

I suppose I should have named it the same as you did in your original code.

In you code you had : Me![IncidentName]

Which I assume came from the DB or a Text box.
I also assumed that this variable(Me![IncidentName]
) was dynamic.

IName should be a variable that holds the Incedent ID or Name.(I am not sure because I dont know how you DB is set up)

If your application does not contain any sensitive data I would be more that happy to take a look at your application as a whole (I don't like to leave anything halfway done) There are a few ways this could be done.
Email the app.
If you have XP we could use messenger to share screens etc..

Ohterwise I will try to help on any other specific questions you have.

Let me know


DotNetDoc
M.C.S.D.
---------------------------------------

Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb

-----------------------------------

If you can't explain it simply, you don't understand it well enough.
- A. Einstein





 
I am happy to give you the two forms involved with access.mdb backend if thats easiest, I presume the problem is there regardless of backend type

This is the current state of play..... in summary

Our access application is extensively based on forms that are linked from the main form by a key field
(.net equivalent in Microtools conversion of our code is I presume, keyname= "IncidentName" which is an integer field that links all our SQL tables together .

In access the connection string is as follows:
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmCtlMainRequestAssistance"

stLinkCriteria = "[IncidentName]=" & Me![IncidentName]
DoCmd.OpenForm stDocName, , , stLinkCriteria

We have been trying to get the equivalent going in .net with limited success, A sample form open OK when opened independently or with
Response.Redirect("frmCtlMainRequestAssistance.aspx) from a button on the main form

We have tried
Response.Redirect("frmCtlMainRequestAssistance.aspx?IncidentName=" & IName ) 'main form
with this on the page loader of second form
Dim Incident as Integer
Incident = Request.QueryString("IName")

and this on the connection and selection strings
'sql database connection string provided by Micrtools
databasespec="Provider=Sqloledb;Data Source=(Local);Initial Catalog=AIMSxpSQL;integrated security = SSPI"
keyname="IncidentName"
'SQL Control Source
controlsource ="SELECT *FROM dbo.tblMainDetails where incidentname = incident"

From reading, because our solution would be primarily intranet based we possibly should be using Server.Transfer anyway however any assistance you can give would be
greatly appreciated...TIA Ken
 
I have to finish up some work right now. Why dont you send me the two files and access db (in a zip file) to

eganenterprises@msn.com

and I will take a look at it in the am.

DotNetDoc
M.C.S.D.
---------------------------------------

Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb

-----------------------------------

If you can't explain it simply, you don't understand it well enough.
- A. Einstein





 
I finally had a chance to look at your code.

That tool sure makse spagetti code.

First thing first

You cant use a Querysting in Server.Transfer. If you would like to use that instead of Response.Redirect then you will have to look into the Context.Items collection to hold your data. You can also pass form data as well.

Here is an article to look at if you want to do that

Second. We need to know where the Incident Name is coming from . Is it from a text box or a db like below

ID=xtable.Rows(icurrent)("IncidentName").ToString()



DotNetDoc
M.C.S.D.
---------------------------------------

Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb

-----------------------------------

If you can't explain it simply, you don't understand it well enough.
- A. Einstein
 
I looked at the artical and think that Response.Redirect seems to be the solution? User frindenly is our main cosiderations.


Sub FillForm(xcurr As Integer)
If(xcurr>0)Then
Dim icurrent As Integer
Dim zstrSQL As String
icurrent=xcurr-1
IncidentName.Text=Convert.ToString(xtable.Rows(icurrent)("IncidentName"))
------------------------------------------------------------

'Does this answer all questions

I belive this string looks at the DB. The Incident Name is the primary key and relation ship link. Currently we use a primary form containg the incident name this form then is linked to a sub form(table) containing the primary key being incident name alowing a one to many relation ship between table 1 and table 2.


Thanks

Regards
Dallas
-------------------



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top