I'm not sure exactly how you have it set up, but try this and see if it works:
In modelbuilder, you can go to "Insert", "Model Only Tools", and select "Parse Path." This tool will read your input and give you either the File Name, Path, Name, or Extension (these are defined by you).
Put two of them in your model and make a variable from the "Input data Element" for one of them. Then, make that a model parameter for the user to set the input Geodatabase. Then connect that input variable to the other Parse Path tool, so you have one input going to both of them. Set one of the tools up to read "Path" and the other to read "File." Both outputs will be the "in-line variables" in your model. Rename the output elements whatever you want--in this case, I would name them "Path" and "File," respectively. I attached an example of how it should look.
From then on, when you want to write to that geodatabase in your model, set the output path of your tool (like the dissolve) to "%Path%\%File%\output_file_name" . This has worked successfully for me through very complex models, even using sub-models.
Tyler Bragg
West Virginia Property Tax Division