PDA

View Full Version : Solved: Using fields in msgbox text



kah
06-19-2007, 10:29 PM
I need to be able to place field data in a msgbox.
I have a table that will only ever hold one record.
Lets say its tbl_company_info
Fields are company_name, company_phone etc

I need to be able to display tbl_company_info.company_name and tbl_company_info.company_phone in msgbox text.

eg

Dim comp_msg, comp_style, comp_title, comp_response

comp_msg = "Company name is : " [ this is where I want tbl_company_info.company_name] & vbCrLf & "Company phone number is: " [this is where I want tbl_company_info.company_phone]

comp_style = vbYesNoCancel + vbInformation
comp_title = "Check company information"
comp_response = MsgBox(comp_msg, comp_style, comp_title)

Sorry if its a silly question!!

geekgirlau
06-19-2007, 11:44 PM
Dim comp_msg As String
Dim comp_style As String
Dim comp_title As String
Dim comp_response As Integer

comp_msg = "Company name is : " & _
DLookup("[company_name]", "tbl_Company_Info") & vbCrLf & _
"Company phone number is: " & _
DLookup("[company_phone]", "tbl_Company_Info")

comp_style = vbYesNoCancel + vbInformation
comp_title = "Check company information"
comp_response = MsgBox(comp_msg, comp_style, comp_title)


A couple of things to note:

DLookup will return Null if the field is empty, so it's usually a good idea to either test for Null, or use nz(DLookup("[company_name]", "tbl_Company_Info"),"") to cope with potential empty fields.

You need to declare the variable type you are using, otherwise all your variables are variants, which takes up more space than required.

kah
06-20-2007, 12:08 AM
Fabulous, thank you.

geekgirlau
06-21-2007, 05:06 PM
My pleasure - don't forget to mark this thread as "Solved" (using the Thread Tools at the top of the page)