using variable or a variable string in a Msgbox

Need help with syntax.

I would like to display the cityname, state (if applicable), & country name within the message in the message box.  these values come from the form CountryRecid, combo. column(1) and StateRecid.column(1) and the city name which is txtbox.

Private Sub cmdAdd_Click()
'Dim gCountryID As Integer
'Dim gStateID As Integer
'Dim gCityName As String
Dim n As Integer
Dim nName As String
   On Error GoTo cmdAdd_Click_Error

gCountryID = Nz([Forms]![frmAddLocation]![CountryRecID])
gStateID = Nz([Forms]![frmAddLocation]![StateRecID])
gCityName = Nz([Forms]![frmAddLocation]![CityName])
    
    n = DCount("*", "tblCity", "[CityName] Like '*" & gCityName & "*' " & _
        "AND [CountryRecID] = " & gCountryID & " " & _
        "AND [StateRecID] = " & gStateID & "")

        If n = 0 Then
            DoCmd.RunSQL _
                ("INSERT INTO tblCity ( CountryRecID, StateRecID, CityName, TaxInclusive, Top5000, DateCreated, Modifiedby ) " _
                & "VALUES ( '" & gCountryID & "', '" & gStateID & "', '" & _
                gCityName & "', " & gTaxIncl & ", " & gTop & ", Date(), '" & _
                GetgUserID() & "' )")
        Else
[b]'        nName = gCityName & ", " & [Forms]![frmAddLocation]![StateRecID].Column(1) & ", " & [Forms]![frmAddLocation]![CountryRecID].Column(1)
'       Debug.Print nName
            Select Case MsgBox("Records Found & ", "  & gCityName &   , vbYesNo Or vbExclamation Or vbDefaultButton1, ")[/b]

                Case vbYes

                Case vbNo

            End Select

        End If

   On Error GoTo 0
   Exit Sub

cmdAdd_Click_Error:

    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdAdd_Click of VBA Document Form_frmAddLocation"

End Sub

Open in new window

Karen SchaeferBI ANALYSTAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dale FyeCommented:
What do you want it to look like?

You describe it well, but I'm not sure whether you are trying to put this in the messagebox in the error handler, or somewhere else within your code.  The way to create a string variable with that information would look something like:

strLocation = (me.txt_CityName + ", ") & (me.cbo_StateRecID.column(1) + ", ") _
                     & me.cbo_CountryRecID.Column(1)

I used the + sign to concatenate some of these strings to the associated commas so that the comma will not appear if the City or State value is NULL.
0
Karen SchaeferBI ANALYSTAuthor Commented:
Cityname, State, Country

strLocation = (Me.CityName + ", ") & (Me.StateRecID.Column(1) + ", ") _
                     & Me.CountryRecID.Column(1)


now what is the proper syntax to get strlocation within the msgbox?
0
Karen SchaeferBI ANALYSTAuthor Commented:
Select Case MsgBox("Records Found, & "'"  & strLocation & "'" &, vbYesNo Or vbExclamation Or vbDefaultButton1, ")
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Dale FyeCommented:
I would do:

strMsg = "Records found, " & strLocation
Select Case msgbox(strmsg, vbYesNo+VbExclamation + vbDefaultButton1)
   Case vbYes

   Case vbNo

   Case else
       Msgbox "Something is extremely wrong, that message " & vbcrlf _
                   & "box should only return vbYes or vbNo!"
End Select
0
Karen SchaeferBI ANALYSTAuthor Commented:
thanks that work, do you know the best way to clear an unbound form - it is part of the results of the msgbox.

                    Me.txtCountryName.Value = ""
                    Me.CountryRecID.Value = ""
                    Me.StateRecID.Value = ""
i get error msg - You can assign a value to this object in procedure
0
Dale FyeCommented:
What procedure are you trying to use?  I normally set those values to NULL, but in Access, you don't have to refer to the Value property, simply:

me.txtCountryName = NULL
me.CountryRecID = NULL
me.StateRecID = Null

BTW, I see you prefixed your CountryName control with "txt", why didn't you prefix the other two with "cbo"?  I generally rename all of my controls on my forms so that I know what type of control I'm refering to.  By default, Access will assign your data controls the name of the field that they are bound to, so when you refer to:

me.CountryRecID

you could be referring to a control, or actually to the field that is part of the forms recordsource, although the proper syntax for referring to the field would be:

me!CountryRecID

if you use a naming convention, you will always know whether your code refers to a control or a field.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Karen SchaeferBI ANALYSTAuthor Commented:
I know being lazy.
0
Karen SchaeferBI ANALYSTAuthor Commented:
no tried you suggestion however, still getting same error does it matter that it is an unbound form?
0
Dale FyeCommented:
Shouldn't matter that it is unbound.

What event are you using for to reset these values?

I rarely use unbound forms, have you tried:

me.undo
0
Karen SchaeferBI ANALYSTAuthor Commented:
Thanks for the input, however, this project was cancelled I no longer need assistance with this issue.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.