Integrated Application Platform › Forums › General › Printing from a button
- This topic has 6 replies, 2 voices, and was last updated 10 years, 11 months ago by
Anonymous.
-
AuthorPosts
-
December 12, 2012 at 3:46 pm #742
Anonymous
InactiveOne problem solved leads to another. I am trying to print a Bill after the data has been entered onscreen. I call the print function but I am doing something wrong and get an error on the query. I have tried numerous things with no luck. Below is te code:
Controller
{Controls:
#(Record
(Access bol
startNew: true
title: ‘Bill of Lading’
nextNum: #(field: bill_num,
table: bol_nextnum, table_field: nextnum)
(Vert
(Horz
(Static, ‘Cosignee Name:’)
#(Key “cosignee_db” field:”cosign_name” fillin:(shipper_num, cosign_name, cosign_address, cosign_city, cosign_st, cosign_zip)))
(cosign_address)(Horz
cosign_city (Skip 2) cosign_st (Skip 2) cosign_zip)Skip
(Horz (Skip 400)(Static, ‘Bill of Lading Information’, font: ‘Arial’, size: 16, weight: 600))
Skip
Skip
Skip
(Horz bill_date (Skip 450) bill_num)
cosignee_name
(Horz (Static, ‘ ‘) export (Skip 535) ship_num)
Skip
(Horz carrier (Skip 343) trailer_num)
Skip
material
Skip
booking
po
release
load
vessel
voyage
seal
Skip
gross_wt
tare_wt
net_wt
Skip
Skip
(Horz (Skip 450)
(Button ‘Print’, size: 16))
)
))
On_Print()
{
data = .Data.Get()
Print_Bol(data.bill_num)
}}
function(bill_num)
{
Window(Object(‘Params’
Object(QueryFormat
{
Query()
{
return “bol where bill_num is ” $ .Data.bill_num $ ” sort bill_num”
}
Output()
{
return Object(“Vert”
#(“Text”, “This is a test”))
}
}
)
bill_num: bill_num
title: “BOL Print”
name: “Bol_bol_print”
))
}December 12, 2012 at 4:47 pm #954amckinlay
KeymasterYou’re very close.
– bill_num: bill_num needs to be inside the Object (just move it up one line)
– it needs to be Bill_num: bill_num to make it public so it can be accessed inside the QueryFormat class
– in the query it should be just .Bill_num
Or alternately you could do Data: Object(bill_num: bill_num) and then reference it as .Data.bill_num
Also, I would get in the habit of using Display when merging values into queries
“bol where bill_num is ” $ Display(.Bill_num) $ ” sort bill_num”
This ensures that the value is quoted if it’s a string. This isn’t strictly necessary if the value is a number, but it prevents the equivalent of SQL injection issues.
December 12, 2012 at 8:14 pm #955Anonymous
InactiveThat seems to have gotten the query to work, but it appears that the value of bill_num is not being passed to the function. I am using an Alert and its giving a null value. I am reposting the corrected function code. The main prog was not changed.
function(bill_num)
{
Window(Object(‘Params’
Object(QueryFormat
{
Query()
{
Alert(.Bill_num) //”returns null value”
return “bol where bill_num is ” $ Display(.Bill_num) $ ” sort bill_num”
}
Output()
{
return Object(“Vert”
#(“Text”, “This is a test”))
Print(‘Test’)
}
}
Bill_num: bill_num
)
title: “BOL Print”
name: “Bol_bol_print”
))
}December 12, 2012 at 8:28 pm #956amckinlay
KeymasterHere’s a simple example that works for me. I had to use .Access.GetData() instead of just .Data
Controller
{
Controls: #(Access 'stdlib' (Vert name (Button Print)))
On_Print()
{
id = .Access.GetData().name
Dialog(.Window.Hwnd, Object('Params'
Object(QueryFormat
{
Query()
{
return "stdlib where name is " $ Display(.Data.id) $ " sort name"
}
}
Data: Object(id: id)
)
title: "BOL Print"
name: "Bol_bol_print"
))
}
}Note: Normally we would use Dialog(.Window.Hwnd, … instead of Window
December 13, 2012 at 1:11 pm #957Anonymous
InactiveI implemented the code as you suggested. It seems to almost work. It is reading the bill_num into the query but the query does not find that record. It acts like the current record has not been saved yet. If I change the id= line to id =.Access.GetData().bill_num – 1, It works fine to bring up the prev record. Below is the code:
Controller
{Controls:
#(Access ‘bol’
startNew: true
title: ‘Bill of Lading’
nextNum: #(field: bill_num,
table: bol_nextnum, table_field: nextnum)
(Vert
(Horz
(Static, ‘Cosignee Name:’)
#(Key “cosignee_db” field:”cosign_name” fillin:(shipper_num, cosign_name, cosign_address, cosign_city, cosign_st, cosign_zip)))
(cosign_address)(Horz
cosign_city (Skip 2) cosign_st (Skip 2) cosign_zip)Skip
(Horz (Skip 400)(Static, ‘Bill of Lading Information’, font: ‘Arial’, size: 16, weight: 600))
Skip
Skip(Horz bill_date (Skip 450) bill_num)
cosignee_name
(Horz (Static, ‘ ‘) export (Skip 535) ship_num)
Skip
(Horz carrier (Skip 343) trailer_num)
Skip
material
Skip
booking
po
release
load
vessel
voyage
seal
Skip
gross_wt
tare_wt
net_wt
Skip
Skip
(Horz (Skip 450)
(Button ‘Print’, size: 16))
)
)
On_Print()
{
id = .Access.GetData().bill_num
Dialog(.Window.Hwnd, Object(‘Params’
Object(QueryFormat
{
Query()
{
Alert(.Data.id)
return “bol where bill_num is ” $ Display(.Data.id) $ ” sort bill_num”
}
Output()
{
return Object(“Vert”
#(“Text”, “This is a test”)
#(bill_num))
Print(‘Test’)
}
Before()
{
Object(“Vert”
#(“Text”, “Before”))
}
}
Data: Object(id: id)
)
title: “BOL Print”
name: “Bol_bol_print”
))
}}
Sorry to be causing so much trouble.
BennyDecember 13, 2012 at 3:25 pm #958amckinlay
KeymasterNo worries. Yes, you do have to ensure the record is saved for this kind of thing. Just call .Access.Save() at the beginning of your On_Print method.
December 14, 2012 at 5:40 pm #959Anonymous
InactiveThat did the trick. I think I am ready to finish implementing everything now. Thanks for all ur help.
Benny
-
AuthorPosts
- You must be logged in to reply to this topic.