Form Field Hyperlink to open record in another form (1 Viewer)

kobiashi

Registered User.
Local time
Today, 21:27
Joined
May 11, 2018
Messages
258
hi

i am trying to open a record into another form from a hyperlink in a field,

i have the VBA code of

Code:
Private Sub txtTancNumber_Click()
    Const cstrForm As String = "frm_NewCavityTanc"
    DoCmd.OpenForm cstrForm, WhereCondition:="[Tanc_ID]=" & Me.txtTancNumber
End Sub

When I click on the hyperlink, a pop up box appears asking for the Tanc_ID,

how can i stop this and open the record straight into the form
 

June7

AWF VIP
Local time
Today, 12:27
Joined
Mar 9, 2014
Messages
5,490
If Tanc_ID is actually a text field, parameter needs apostrophe delimiters.

DoCmd.OpenForm "frm_NewCavityTanc", , , "Tanc_ID='" & Me.txtTancNumber & "'"

Why are you declaring a constant for form name?
 

kobiashi

Registered User.
Local time
Today, 21:27
Joined
May 11, 2018
Messages
258
Hi thanks for the reply


I've only just started using Access, so I'm still learning.


not sure if this matters for the issue, but this form is bound to a query
 

kobiashi

Registered User.
Local time
Today, 21:27
Joined
May 11, 2018
Messages
258
Tanc_ID is in the query

Tanc_ID is the primary key in a table so its an autonumber
 

June7

AWF VIP
Local time
Today, 12:27
Joined
Mar 9, 2014
Messages
5,490
Although not really correct usage, I think the Const should work but it is unnecessary complication. Eliminate and explicitly reference form name in the OpenForm command, without the apostrophes. That should also work.
 

kobiashi

Registered User.
Local time
Today, 21:27
Joined
May 11, 2018
Messages
258
so is this correct?

Code:
Private Sub txtTancNumber_Click()
    DoCmd.OpenForm frm_NewCavityTanc, WhereCondition:="[Tanc_ID]=" & Me.txtTancNumber
End Sub
 

June7

AWF VIP
Local time
Today, 12:27
Joined
Mar 9, 2014
Messages
5,490
The explicit form name must be within quotes as it is a string, not a declared variable. See my example again.
 

kobiashi

Registered User.
Local time
Today, 21:27
Joined
May 11, 2018
Messages
258
so this is what i've got
Code:
Private Sub txtTancNumber_Click()
    DoCmd.OpenForm "frm_NewCavityTanc", WhereCondition:="[Tanc_ID]=" & Me.txtTancNumber
End Sub


see screenshot for the outcome
 

Attachments

  • access.PNG
    access.PNG
    9.6 KB · Views: 81

June7

AWF VIP
Local time
Today, 12:27
Joined
Mar 9, 2014
Messages
5,490
What happens when you click OK on that popup?

What is the SQL statement of the form RecordSource?

You might have to provide db for review because that code should work.
 

kobiashi

Registered User.
Local time
Today, 21:27
Joined
May 11, 2018
Messages
258
When i click on the popup, the form opens but is empty

Record source for the form is Query_Tanc, which is the query i want to use


database is too bog to upload

but i can provide google drive link
 

June7

AWF VIP
Local time
Today, 12:27
Joined
Mar 9, 2014
Messages
5,490
Next time, run Compact & Repair then send the file to a Windows Compressed folder and attach the zip.
 
Last edited:

June7

AWF VIP
Local time
Today, 12:27
Joined
Mar 9, 2014
Messages
5,490
Tanc_ID is not a field in that RecordSource query. TancNumber is.

The field is not in the field grid.
 

kobiashi

Registered User.
Local time
Today, 21:27
Joined
May 11, 2018
Messages
258
it is on mine, maybe i didnt save it before uploading it to my drive
 

June7

AWF VIP
Local time
Today, 12:27
Joined
Mar 9, 2014
Messages
5,490
Well, I add field to the design grid and code works.
 

kobiashi

Registered User.
Local time
Today, 21:27
Joined
May 11, 2018
Messages
258
are you talking about this view?
 

Attachments

  • access1.PNG
    access1.PNG
    42 KB · Views: 84

June7

AWF VIP
Local time
Today, 12:27
Joined
Mar 9, 2014
Messages
5,490
frm_NewCavityTanc is bound to Query_NewCavityTanc which did not have Tanc_ID field selected.

So, no, not the query in the image you posted.
 

kobiashi

Registered User.
Local time
Today, 21:27
Joined
May 11, 2018
Messages
258
Ah, i understand now

i've added it to Query_NewCavityTanc

now the form opens, but the record is empty
 

June7

AWF VIP
Local time
Today, 12:27
Joined
Mar 9, 2014
Messages
5,490
Okay, error goes away. Sorry, didn't look at textbox. The textbox has TancNumber value, not Tanc_ID.

Change code to reference Tanc_ID field, not the textbox. Or put another textbox on form bound to Tanc_ID (can be not visible).

DoCmd.OpenForm "frm_NewCavityTanc", WhereCondition:="[Tanc_ID]=" & Me!Tanc_ID
 

Users who are viewing this thread

Top Bottom